Working with branches

Creating

git checkout -b $branchname
git push origin $branchname --set-upstream

Creates a new branch locally then pushes it.

Getting from remote

git fetch origin
git checkout --track origin/$branchname

Gets a branch in a remote.

Delete local remote-tracking branches

git remote prune origin

Deletes origin/* branches in your local copy. Doesn’t affect the remote.

List existing branches

git branch --list

Existing branches are listed. Current branch will be highlighted with an asterisk.

List merged branches

git branch -a --merged

List outdated branches that have been merged into the current one.

Delete branch forcefully

git branch -D $branchname

Delete a branch irrespective of its merged status.

Delete remote branch

git push origin :$branchname

Works for tags, too!

Get current sha1

git show-ref HEAD -s
0 Comments for this cheatsheet. Write yours!