Skip to content

This is a cheat sheet of 100 commonly used commands in Git Bash, organized from basic to advanced, and from most used to least used. Each command includes a short explanatory comment.

License

Notifications You must be signed in to change notification settings

plexoio/gitcommands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Git Bash Commands Cheat Sheet

This is a cheat sheet of 100 commonly used commands in Git Bash, organized from basic to advanced, and from most used to least used. Each command includes a short explanatory comment.

Concept

Basic Commands

  1. git init # Initialize a new Git repository
  2. git config user.name "<name>" # Set your Git username
  3. git config user.email "<email>" # Set your Git email
  4. git status # Check the status of your repo
  5. git add <file> # Add a file to the staging area
  6. git add . # Add all files to the staging area
  7. git commit -m "<message>" # Commit changes with a message
  8. git log # View commit history
  9. git log --oneline # View commit history in compact format
  10. git diff # Show changes between working directory and the last commit
  11. git diff <branch1> <branch2> # Show changes between two branches
  12. git show <commit> # Show changes made in a specific commit
  13. git ls-files # List all files tracked by Git
  14. git blame <file> # Show who changed what in a file
  15. git bisect # Find the commit that introduced a bug
  16. git reflog # Show a log of all local commits
  17. git cat-file -p <commit> # Display the content of a commit object
  18. git rev-parse <ref> # Get the SHA-1 hash of a reference
  19. git fsck # Verify the integrity of the repository
  20. git gc # Clean up unnecessary files and optimize the repository

Remote Repositories

  1. git remote add origin <url> # Connect local repo to remote
  2. git push -u origin <branch> # Push changes to remote branch
  3. git pull # Pull changes from remote repo
  4. git clone <url> # Clone a remote repository
  5. git remote -v # List remote connections
  6. git remote rm <remote> # Remove a remote connection
  7. git fetch # Fetch updates from remote repo without merging
  8. git remote show <remote> # Show details about a remote repository
  9. git remote rename <old-name> <new-name> # Rename a remote repository
  10. git push --tags # Push all tags to remote repository
  11. git push --force # Force-push changes to the remote repository
  12. git push origin --delete <branch> # Delete a remote branch
  13. git pull --rebase # Pull and rebase the current branch
  14. git fetch --all # Fetch updates from all remote repositories
  15. git remote update # Update remote-tracking branches

Branching & Merging

  1. git branch # List all branches
  2. git branch <branch> # Create a new branch
  3. git checkout <branch> # Switch to a branch
  4. git checkout -b <branch> # Create and switch to a new branch
  5. git merge <branch> # Merge a branch into the current branch
  6. git branch -d <branch> # Delete a branch
  7. git branch -r # List remote branches
  8. git branch -a # List local and remote branches
  9. git branch -u <upstream-branch> # Set upstream branch for the current branch
  10. git branch -m <old-name> <new-name> # Rename a branch
  11. git branch --merged # List branches that have been merged into the current branch
  12. git branch --no-merged # List branches that have not been merged into the current branch
  13. git merge --abort # Abort an ongoing merge operation
  14. git merge --squash <branch> # Squash the commits from a branch into a single commit
  15. git merge --no-ff <branch> # Merge with a merge commit even if it's a fast-forward merge

Stashing

  1. git stash # Save changes for later
  2. git stash list # List stashed changes
  3. git stash apply # Apply stashed changes
  4. git stash drop # Remove a stash
  5. git stash pop # Apply and remove the latest stash
  6. git stash branch <branch> # Create a new branch and apply a stash
  7. git stash save "<message>" # Save changes with a custom stash message
  8. git stash clear # Remove all stashed changes
  9. git stash apply <stash> # Apply a specific stash
  10. git stash drop <stash> # Remove a specific stash

Rebase & Cherry-picking

  1. git fetch # Fetch updates from remote repo
  2. git rebase <branch> # Rebase current branch onto another
  3. git cherry-pick <commit> # Apply a specific commit
  4. git rebase --abort # Abort an ongoing rebase operation
  5. git rebase --continue # Continue a paused rebase operation
  6. git rebase --skip # Skip a conflicting commit during rebase
  7. git cherry-pick --continue # Continue a paused cherry-pick operation
  8. git cherry-pick --abort # Abort an ongoing cherry-pick operation

Reset, Remove, and Rename

  1. git reset # Reset staging area to match the last commit
  2. git reset <file> # Remove a file from the staging area
  3. git reset --hard # Discard all changes since the last commit
  4. git rm <file> # Remove a file from the repository and working directory
  5. git mv <old-name> <new-name> # Rename or move a file
  6. git clean -f # Remove untracked files from the working directory
  7. git clean -fd # Remove untracked files and directories from the working directory

Tags

  1. git tag # List tags
  2. git tag <tag-name> # Create a lightweight tag
  3. git tag -a <tag-name> -m "<message>" # Create an annotated tag
  4. git push origin <tag-name> # Push a tag to the remote repository
  5. git tag -d <tag-name> # Delete a local tag
  6. git push origin --delete <tag-name> # Delete a remote tag
  7. git tag --contains <commit> # Find tags containing a specific commit
  8. git describe # Describe the most recent tag and commit

Advanced Commands

  1. git submodule add <repository> <path> # Add a Git submodule
  2. git submodule init # Initialize Git submodules
  3. git submodule update # Update Git submodules
  4. git submodule foreach <command> # Execute a command in all submodules
  5. git grep <pattern> # Search for a pattern in the repository
  6. git log -S"<pattern>" # Search for commits that added or removed a pattern
  7. git archive --format=zip --output=<output-file> <branch> # Create a zip archive of a branch
  8. git shortlog # Summarize commit logs by author
  9. git log --graph --decorate --oneline # Display commit history as a graph
  10. git rev-list --count <ref> # Count the number of commits in a branch
  11. git commit --amend # Modify the last commit
  12. git commit --amend -m "<new-message>" # Modify the last commit message
  13. git reflog expire --expire=now --all # Remove all reflog entries
  14. git rev-parse --show-toplevel # Show the root directory of the repository
  15. git config --global alias.<alias-name> '<git-command>' # Create a Git alias
  16. git config --list # List all Git configuration settings
  17. git help <command> # Show help for a Git command

About

This is a cheat sheet of 100 commonly used commands in Git Bash, organized from basic to advanced, and from most used to least used. Each command includes a short explanatory comment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published