Tuesday, June 30, 2020

Git command line cheat sheet

After my previous blog post about introducing the git command line, here is a table of all the commands I regularly use in git:

The basics

CommandExplanation
git init .
Make the current directory a git repository.
git status
Get information about the current state of the repository.
git add (path)
Add a modified file to the git index. Use '.' for path in order to add all modified files.
git rm (path)
Remove a modified file from the git index.
git diff
Get the file changes from what is in the git index to what is in the currently modified file.
git commit
Take a snapshot backup of the current index.
git log
Get a list of commits made.
git tag -a "(tag name)"
Tag the last commit with a special name (can be used to mark version numbers).
git tag
List existing tags.
git reset --hard HEAD
Return to the last commit (permanently remove any uncommitted changes).


Branches

CommandExplanation
git branch (branch name)
Create a new branch.
git branch --list
List existing branches.
git branch --delete (branch name)
Delete an existing branch.
git checkout (branch name)
Jump to a different branch.
git merge (branch name)
Merge the given branch into the current branch so that they become one branch.
git stash push
Stash any file changes without committing them in order to jump to another branch.
git stash pop
Retrieve back stashed file changes.
git log --graph
Like log but will show how commits in different branches are connected together.