Sat, 17 Nov 2012

Git cheatsheet

Keywords: git

Merge newer changes on the branch you came from (eg master):

$ git rebase master

Merge your branch:

$ git merge [--no-ff] newbranch

Push a newly created branch upstream:

$ git push -u origin newbranch

-u makes your branch a tracking branch of upstream


Create a new tracking branch:

$ git branch -t newbranch origin/newbranch

Delete remote-tracking branch:

$ git branch -r -d origin/oldbranch

Delete remote branch: (see also

$ git push origin --delete oldbranch

Rewrite history:

$ git rebase -i HEAD~5

Make a branch retroactively (see

$ git checkout -b newbranch
$ git update-ref refs/heads/master origin/master

Merge a branch that should have been rebased:

$ git fetch upstream_branch:local_newbranch
$ git checkout local_newbranch
$ git rebase master
$ git checkout master
$ git merge -ff-only local_newbranch
$ git branch -d local_newbranch

Create a branch for a pull request:

$ git pull upstream_branch:local_newbranch

Move a branch to a new commit:

$ git branch -f branch_name new_tip_commit

Look at a file from an previous revision:

$ git cat-file -p <sha1>:filename

[/revision_control] permanent link

November 2022
Sun Mon Tue Wed Thu Fri Sat