Back to: Git Course
Git is an incredibly powerful tool for version control and collaborative software development. However, mastering Git can be a daunting task, with its many commands and complex workflows. That’s where a Git cheat sheet comes in handy. A Git cheat sheet is a quick reference guide that lists all the essential Git commands and shortcuts in one place, making it easier for beginners and pros alike to navigate Git with ease. In this tutorial, we’ll provide a detailed Git cheat sheet that covers all the essential Git commands and categories, from basic repository setup to advanced branching and merging. So, whether you’re new to Git or a seasoned pro, this Git cheat sheet is sure to be a valuable resource in your arsenal.
Repository Creation and Cloning
Git Command | Description |
---|---|
git init | Initializes a new Git repository |
git clone <url> | Clones a repository from a URL |
Branching
Git Command | Description |
---|---|
git branch | Lists all local branches |
git branch <name> | Creates a new branch |
git checkout <branch> | Switches to a branch |
git merge <branch> | Merges a branch into the current branch |
git branch -d <branch> | Deletes a branch |
Staging Changes
Git Command | Description |
---|---|
git add <file> | Adds changes to the staging area |
git add . | Adds all changes to the staging area |
git reset <file> | Removes changes from the staging area |
git reset --hard | Discards all local changes |
Committing Changes
Git Command | Description |
---|---|
git commit -m "<message>" | Commits changes with a message |
git commit -a -m "<message>" | Commits all changes with a message |
git commit --amend | Changes the last commit |
Viewing Changes
Git Command | Description |
---|---|
git status | Shows the status of the working tree |
git log | Shows the commit history |
git diff <file> | Shows the differences between files |
git diff --staged | Shows the differences between staged and committed files |
Remote Repositories
Git Command | Description |
---|---|
git remote add <name> <url> | Adds a remote repository |
git push <remote> <branch> | Pushes changes to a remote repository |
git pull <remote> <branch> | Pulls changes from a remote repository |
git fetch <remote> | Fetches changes from a remote repository |
Stashing Changes
Git Command | Description |
---|---|
git stash | Stashes changes in the working directory |
git stash list | Lists all stashes |
git stash apply <stash> | Applies a stash |
git stash drop <stash> | Deletes a stash |
Miscellaneous
Git Command | Description |
---|---|
git config --global user.name "<name>" | Sets the user name for all repositories |
git config --global user.email "<email>" | Sets the email for all repositories |
git rm <file> | Removes a file |
git mv <oldname> <newname> | Renames a file |
git tag <name> | Creates a new tag |
git tag | Lists all tags |
git tag -d <name> | Deletes a tag |
Follow us on social media
Follow Author