Git Cheat-Sheet

Mar 4, 2014

Here is a git cheat-sheet of my frequently used commands.

Basic Usage

git init
initializes git in a local folder

git status
shows status of the pwd

git add filename
stages untracked items

`git commit -m "message"`` commits staged files to repo with a message

git log
shows commit history

git remote add [alias] [url]
adds a remote repository named [alias] at [url]

git pull -u [alias] [branch]
pulls the [branch] branch of [alias] repository

git push [alias] [branch]
pushes the local commits to remote repo

git push -u origin [branch] pushes the local branch named [branch] to [alias]

git checkout [branch]
move to the branch named [branch]

git checkout -b [branch]
create a branch named [branch] and move to it

Tag management

git tag tag_name create a tag at current commit

git tag -l or git tag --list list all tags

git tag new old create alias of an old tag

git tag -d tag_name remove an existing tag


With great power comes great responsibility.

git push --force origin fix
Forcefully push, useful for rewriting history

find . -type f | grep -i .git | xargs rm
A brute-force way of removing git from the current directory.

git branch | grep 'pattern' | xargs git branch -D
Remove all branches that match a given regular expression

git branch --merged master | egrep -v "(^\*|master|develop|origin)" | xargs git branch -D
Remove all branches that are merged to master

git push origin --delete <branchName> or git push origin :<branchName>
Removes a branch in remote repository

git push --tags Push a tags to remote