Skip to content

Latest commit

 

History

History
110 lines (70 loc) · 2.46 KB

git-cheat-sheet.md

File metadata and controls

110 lines (70 loc) · 2.46 KB

Here's a cheat sheet for essential Git commands:

Configuration:

  1. Configure Git user information:
    • git config --global user.name "Your Name"
    • git config --global user.email "[email protected]"

Creating Repositories:

  1. Initialize a new Git repository:

    • git init
  2. Clone an existing repository:

    • git clone <repository_url>

Basic Workflow:

  1. Check the status of your working directory:

    • git status
  2. Add changes to the staging area:

    • git add <file> (or git add . to add all changes)
  3. Commit changes with a message:

    • git commit -m "Your commit message"
  4. Push changes to a remote repository:

    • git push

Branches:

  1. Create a new branch:

    • git branch <branch_name>
  2. Switch to a different branch:

    • git checkout <branch_name>
  3. Create a new branch and switch to it:

    • git checkout -b <new_branch_name>
  4. List all branches (local and remote):

    • git branch -a
  5. Merge a branch into the current branch:

    • git merge <branch_name>

Updating and Synchronizing:

  1. Pull changes from a remote repository:

    • git pull
  2. Fetch changes from a remote repository:

    • git fetch

Reviewing History:

  1. View commit history:

    • git log
  2. View a simplified, one-line commit history:

    • git log --oneline
  3. View a graphical commit history:

    • git log --graph --oneline --all

Undoing Changes:

  1. Discard changes in the working directory:

    • git checkout -- <file>
  2. Unstage changes:

    • git reset <file>
  3. Amend the last commit (for small changes):

    • git commit --amend

Remote Repositories:

  1. Add a remote repository:

    • git remote add <remote_name> <repository_url>
  2. Remove a remote repository:

    • git remote remove <remote_name>

Tagging:

  1. Create an annotated tag:

    • git tag -a <tag_name> -m "Tag message"
  2. Push tags to the remote repository:

    • git push --tags

Collaboration:

  1. Fetch changes from a remote repository:

    • git fetch
  2. Create a pull request (GitHub/GitLab):

    • Use the web interface of your platform
  3. Merge a pull request (GitHub/GitLab):

    • Use the web interface of your platform

Git Help:

  1. Get help for a specific command:
    • git help <command> or git <command> --help

Remember that Git is a powerful tool with many more commands and options, but these are the essential commands to get you started with version control and collaboration.