简体   繁体   中英

Branches in git merge: relation with the current branch, and whether they are modified by git merge?

In git merge of branches,

  • must one of the branches be the current branch (ie the branch pointed by HEAD?)?

  • Is the current branch called the target branch, and is the other branch(es) said to be merged into the target branch?

  • Is the target branch always not specified to git merge , ie do we only need to specify the non-target branch(es) to git merge ? If yes, is it because the target branch is always the current branch?

  • Does git merge change the target branch only, but not the other branch?

    So is it okay to merge a remote tracking branch (said to be read-only) to the current branch, because the merge does not change the remote tracking branch? (I am reading about the merge step in git pull , which merges a remote tracking branch into the current branch, and I remember a remote tracking branch is read-only)

  • You are right

     git merge <topic> 

    This command will merge the topic branch to the current branch, ie the branch currently pointed to by HEAD

  • There are no naming conventions for the current branch during merge, but yes, in this case, the topic branch is said to have merged into the current branch

  • Only the branch to be merged can be specified. The branch into which the merge happens is always the current branch

  • git merge changes only the current branch. Additional commits can be added to the topic branch and can be merged again.

EDIT:

A remote tracking branch is read-only in as much that it does not contain a working directory. So no changes(read commits) can be made directly to the remote branch. However you can always push changes to the tracking branch

So yes, it is okay to merge a remote tracking branch into the current branch. However the git merge in git pull is optional. You can set git pull to do a git fetch + git rebase if needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM