Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pushing to a branch post merge

If I push to a branch after merging it with master, how will git handle it (Update the latest commits pushed in branch to master automatically OR do nothing OR do something else) ?

like image 630
vikas Avatar asked Jul 08 '13 13:07

vikas


People also ask

What happens if you push to a merged branch?

When you push a branch, you update the remote's pointer to point to the same commit as yours. In addition, your local repo and the remote repo negotiate what snapshots the remote is missing and sends those to the remote. Otherwise, the newly updated remote branch would point at a commit that it knew nothing about.

Can I push after merge request?

Yes. The merge request wil update itself to reflect any new commits pushed since it was created, until you finally merge it.

Can I still use a branch after merge?

When you're done with a branch and it has been merged into master, delete it. A new branch can be made off of the most recent commit on the master branch. Also, while it is ok to hang onto branches after you've merged them into the master they will begin to pile up.

How do I merge to a specific branch?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.


1 Answers

After the merge you still have 2 branches, the one that you merged from and the one that you merged into, which is usually still your active branch.

The new commit will go to branch that is checked out and that is either master or the other branch.

Note, that we don't push to a branch: we commit to a branch and push the branch to a remote repository. And we do not update commits, we add new commits to the repository. Commits never change.

Addition - Sure, you still can push to the "old" branch. And merge it into master again:

A - B - - - E - G      [master]
     \     /   /
      C - D - F        [issue_202]

But I'd prefer creating a new branch to fix the issues. It's a question of workflow. Assume, the work is ticket-based, then the issue_202 ticket goes to resolved before you merge into master. So to my opinion, the additional work is not a fix on the issue_202 but a fix for the master branch and so I would create a new ticket and a new branch to fix the issues:

              F        [issue_202_1]
             / \
A - B - - - E - G      [master]
     \     /  
      C - D            [issue_202] [
like image 76
Andreas Dolk Avatar answered Nov 15 '22 18:11

Andreas Dolk