Let’s say we have the following situation in Git:
A created repository:
mkdir GitTest2 cd GitTest2 git init
Some modifications in the master take place and get committed:
echo "On Master" > file git commit -a -m "Initial commit"
Feature1 branched off master and some work is done:
git branch feature1 git checkout feature1 echo "Feature1" > featureFile git commit -a -m "Commit for feature1"
Meanwhile, a bug is discovered in the master-code and a hotfix-branch is established:
git checkout master git branch hotfix1 git checkout hotfix1
The bug is fixed in the hotfix branch and merged back into the master (perhaps after a pull request/code review):
echo "Bugfix" > bugfixFile git commit -a -m "Bugfix Commit" git checkout master git merge --no-ff hotfix1
Development on feature1 continues:
git checkout feature1
Say I need the hotfix in my feature branch, maybe because the bug also occurs there. How can I achieve this without duplicating the commits into my feature branch?
I want to prevent to get two new commits on my feature branch which have no relation to the feature implementation. This especially seems important for me if I use pull requests: All these commits will also be included in the pull request and have to be reviewed although this has already been done (as the hotfix is already in the master).
I can not do a git merge master --ff-only
: "fatal: Not possible to fast-forward, aborting.", but I am not sure if this helped me.
feature1
is completely local, have a look atgit rebase
. – Diakinesisgit rebase
seems like black magic for me.... – Quentinquercetingit branch feature1
andgit checkout feature1
could be combined intogit checkout -b feature1
and 4. could be entirely reduced togit checkout -b hotfix1 master
– Minestronerebase
should be a last resort, imo, and "manage all conflicts that arise" ... well.) – Oligosaccharidegit fetch && git rebase -i origin/master
is definitely the way to go if your feature branch is local... I'm having the same issue only, the feature branch is in the cloud and several developers are working on it. – Greggit add
. Once they have been committed once, future changes can be automatically added at commit time withgit commit -a
– Receptive