Skip to content

Git Cookbook

Tomasz Drzewiecki edited this page Jan 6, 2017 · 4 revisions

Git Recipies

Fix repository after it diverged with master

When this occurs github writes "your branch is n commits ahead and m commits behind target branch"

  • use git status to make sure you're on master
  • save your local commits as a new branch
git checkout -b <save-branch-name>
  • fetch changes from upstream
git fetch upstream
  • reset your local master to upstrem master state
git reset --hard upstream/master
  • rebase your branch on top of master
git checkout <save-branch-name>
git rebase master
  • fast-forward merge your save branch to master
git checkout master
git merge --ff-only <save-branch-name>
  • override history on your github fork
git push -f origin master

Git info

rebase vs merge

https://www.atlassian.com/git/tutorials/merging-vs-rebasing/the-golden-rule-of-rebasing

Clone this wiki locally