Like most other posts/pages on this site, I am writing this primarily for my own use but am happy if others find it useful as well. My goal is to create a cheatsheet of sorts for Git. It’ll include some more meat on the bones (aka details about various commands) than one sometimes finds on other cheatsheets while at the same time leaving off a number of commands I don’t personally expect to be using.
- git clone <url of repo> – This can operate over ssh or http/s.
- git init – Create a new local repo in the current directory.
- git add . – Add all changes to next commit.
- git commit -a – Add all changes in tracked files.
- git commit – Commits staged changes.
- git remote -v – List all remotes.
- git remote add <shortname> <url> – Add a git repo with the specific shortname.
- git fetch <remote> – Downloads all changes from repo but doesn’t merge with current.
- git pull <remote> <branch> – Downloads all changes from repo and merges.
- git push <remote> <branch> – Push local changes to remote.
- git reset –hard <commit> – Discards local changes; can be set to HEAD or to any specific commit.
- git checkout HEAD <file> – Reverts local changes for specific file.
- git revert <commit> – Revert the changes in a commit by adding another commit reversing changes.
- git branch -av – List all the branches.
- git checkout <branch> – Switch the branch you are currently working with.
- git branch <new-branch> – Create a new branch from current files.
- git branch -d <branch> – Delete a given branch.
- git tag <tag-name> – Tag a commit.
- git merge <branch> – Merge specified branch into current branch.
- git rebase <branch>
- git branch -dr <remote/branch> – Remove a branch from remote.
- git push –tags – Push local tags to remote.
- Tobias Gunther. Git Cheat Sheet. Git Tower, 2/2017.