No idea if this is the best way to do it, but for me it worked to follow the instructions by mcarans on Stackoverflow about How to move files from one git repo to another (not a clone), preserving history
Situation: You create a branch
develop at point X to develop your super cool new feature. You do some commits in your branch. Meanwhile there have been some changes in
develop that you want to have in your new branch. To do this, rebase your branch. Basically, this replays every commit in your branch on top of the current state in the branch you do the rebase against. Do a rebase as follows:
$ git checkout develop Switched to branch 'develop' $ git pull ... $ git checkout newfeature Switched to branch 'newfeature' $ git rebase develop First, rewinding head to replay your work on top of it... Applying: intermediate commit
Before doing this, you need to commit or stash all your changes. During the rebase, if there are conflicts, you need to resolve them one by one for every commit in your branch. You can simplify conflict resolution in one of two ways: use the flag
-Xours to always take the version in the branch that you are rebasing against (
develop in our example); or use the flag
-Xtheirs to always take the version in your branch.
When there are conflicts, you need to resolve them. To resolve a conflict, edit the file that has the conflict and remove all places indicated by
add all the modifications to the staging area. You can commit, but you do not have to. For things that you know they will be resolved later on anyway, you can also chose
git rebase --skip to ignore the problem (e.g., if a file was deleted in your branch and edited in the other and you know you copied the new file into your branch in a later commit). At the end, there may be things you need to commit to finalize the merge, then the rebase is complete. Don’t forget to push the result to your remote branch!
Really throw away everything (all changes!) from the last commit:
git reset --hard HEAD~1
Delete the commit, but preserve all changes:
git reset --soft HEAD~1
For more details and explanations, read this excellent answer by Ryan Lundy on stackoverflow.
From the category "bookmarks/links": A successful Git branching model