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 http://git-scm.com/book/ch3-5.html)

$ git push origin --delete oldbranch


Rewrite history:

$ git rebase -i HEAD~5


Make a branch retroactively (see http://blogs.perl.org/users/mark_leighton_fisher/2012/11/when-to-create-a-branch-in-git.html):

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


Merge a branch that should have been rebased:

$ git fetch https://github.com/user/repo.git 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 https://github.com/user/repo.git 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