torsdag den 26. november 2015

Git Rebase Commands

The goal of this post is to make it easier for me to reference the individual steps of rebasing a Git repository.

I usually push the branch to origin as soon as I have made the first commit for backup purposes. Then I do an interactive rebase when the feature is complete to clean up the branch.

First update develop:


git checkout develop
git pull -u
git checkout feature/branch


Perform the interactive rebase:

git rebase -i develop


Push the feature branch to origin using force. Don't do this if somebody else is working on the same branch.

git push --force


If you don't want to do the rebase interactively, then just rebase:
git rebase develop


git rebase develop

If your current branch contain commits already merged into develop. Or is the continuation of a previous branch merged with develop after the current branch has been created. Then you must apply a little more magic.
Get the hash of the commit immediately before the commits you want to keep. The run the following command with #hash replaced by the hash of the commit.

git rebase --onto master #hash

The changes must be force-pushed.

See more here: https://www.atlassian.com/git/tutorials/merging-vs-rebasing/workflow-walkthrough.

Ingen kommentarer:

Send en kommentar

Bemærk! Kun medlemmer af denne blog kan sende kommentarer.