Git Commands Cheat Sheet
Git Commands Cheat Sheet
The following table shows the most commonly used Git Commands:
Basic Commands | Description |
---|---|
git init | Initialize a local Git Repository |
git add | Add one or more files to the staging area |
git commit -m “Commit Message” | Commit changes to the head but not to the remote repository. |
git status | Check the status of your current repository and list the files you have changed. |
git log | Provides a list of all commits made on a branch |
git diff | View the changes you have made to the file |
git push origin <branch name> | Push the branch to the remote repository so that others can use it. |
git config --global user.name “Name” | Tell Git who you are by configuring the author name |
git config --global user.email [email protected] | Tell Git who you are by configuring the author's email id. |
git clone <repository_name> | Creates a Git repository copy from a remote source |
git remote add origin <server> | Connect your local repository to the remote server and add the server to be able to push it. |
git branch <branch_name> | Create a new branch |
git checkout <branch_name> | Switch from one branch to another |
git merge <branch_name> | Merge the branch into the active branch |
git rebase | Reapply commits on top of another base tip |
git checkout -b <branch_name> | Creates a new branch and switch to it |
git stash | Stash changes into a dirty working directory |
git pull | Update local repository to the newest commit |
git revert <commit_id> | Revert commit changes |
git clean -n | Shows which files would be removed from working directory. Use the -f flag in place of the -n flag to execute the clean. |
git log --summary | View changes (detailed) |
git diff HEAD | Show difference between working directory and last commit. |
git log --oneline | View changes (briefly) |
git reflog | Show a log of changes to the local repository’s HEAD. Add --relative-date flag to show date info or --all to show all refs. |
git rebase -i <base> | Interactively rebase current branch onto <base>. Launches editor to enter commands for how each commit will be transferred to the new base. |
git restore --staged <file_name> | Resetting a staged file |
git rm -r [File_name] | Remove a file (or folder) |
git config --list | List all variables set in config file, along with their values |
git branch -d <local_branch> | Delete local branch in Git |
git push -d <remote_name> <branch_name> | Delete remote branch in Git |
git stash pop | Unstash the changes |
git commit -am | The -am along with the command is to write the commit message on the command line for already staged files. |
git commit -ammend | The amend is used to edit the last commit. Incase we need to change the last committed message, this command can be used. |
git rm | The git rm command is used to remove or delete files from working tree and index. |
git pull --rebase | Git rebase is used to rewrite commits from one branch to another branch. |
git merge --squash | The squash along with git merge produces the working tree. It indexes in the same way as that of the real merge, but discards the merge history. |
git revert -e <commit_id> | edit the commit message before reverting, -e is used for the same. |
git bisect | Git bisect goes through all the previous commit and uses binary search to find the bugged commit. |
git blame | git blame is used to know who/which commit is responsible for the lastest changes in the repository. |
git cherry-pick | Choosing a commit from one branch and applying it to another is known as cherry picking in Git. |
Learn the complete Python programming language
Stay connected with news and updates!
Join our mailing list to receive the latest news and updates from our team.
Don't worry, your information will not be shared.
We hate SPAM. We will never sell your information, for any reason.