User3472688863
User3472688863

Reputation: 3

Commit to a branch that has been merged and open a new pull request

I have a branch A that has already been merged into master. Now I need to add some new commits to the same branch A and open a new pull request. My question is if I commit to the same branch that was already merged, will the commits automatically go into master?

Upvotes: 0

Views: 2855

Answers (1)

knittl
knittl

Reputation: 265141

No, when you merge a branch, a new commit is created. This commit only modifies one branch, namely the target branch. For instance:

git checkout -b feature
# hack hack hack
git add changed files
git commit -m 'implemented my feature'
git checkout master
git merge --no-ff feature
# keep working on feature:
git checkout feature
# hack hack
git add changed files
git commit -m 'polished my feature'

You will have a new merge commit on branch master with 2 parents. You can then continue working on feature, create new commits and create new pull requests or merge requests. If you want the new commits to be part of master, you have to merge them again. Git is smart enough to figure out which commits are new and which commits have already been merged before.

Upvotes: 2

Related Questions