I wish to share a useful git gist that I use on my workflow. I saw this on meagar's gist few years ago
Rebase "feature/my_branch" onto master
if you work solo on the branch...
$ git checkout feature/my_branch # make sure you're on the right branch
$ git fetch # update remote refs
$ git rebase origin/master # perform the rebase from master
# for each conflict, edit file, resolve conflicts, git add -u <file>, git rebase --continue
$ git push -f origin feature/my_branch # overwrite remote branch with newly rebased branch
if you work with someone else on a branch...
Don't rebase!, The author who is working on the branch follows the steps above, then all other contributors do this...
$ git checkout feature/my_branch # make sure you're on the right branch
$ git fetch # update remote refs
$ git reset --hard origin/feature/my_branch # discard the state of your branch, move to the newly rebased branch
Rebase "feature/my_branch" onto master, squashing all commits
$ git checkout feature/my_branch
$ git fetch
$ git reset --hard origin/master # move your branch to the current state of master
$ git merge --squash head@{1} # merge all changes from your branch into the index
$ git status # verify changes to be committed
$ git commit # edit all commit messages from previous commits down to a single sane commit message
$ git push -f feature/my_branch # overwrite remote branch with newly rebase branch
Top comments (0)