How does it happen that someone is pushing his/her codes into other's branch without branching out to that specific branch?

Viewed 32

For example:

Person A is working in the X branch.
Person B is working in the Y branch.
Person C pulled the codes from Person B's branch by rebasing and git fetch.
Because it wasn't doing the fast-forwarding.

Now the problem is whenever Person A and Person B commit and push their codes into their branches and in GitHub, it shows that it pushed into that Person C's branch.

Can anyone please explain why it's happening?

1 Answers

When you git push with no further arguments, you push to the local branch's remote tracking branch", sometimes also called the upstream branch. For example, branchA might track origin/branchA. But it does not have to be so. branchA could track origin/branchC.

You can see what all your local branches are tracking with git branch -vv.

branchA  24c27e21 [origin/branchA] Description of the last commit to branchA

The tracking branch is usually set up automatically, this can be controlled with branch.autoSetupMerge. It can also be set manually when creating a branch with git branch --track and changed with git branch --set-upstream-to.

Note that this is all part of the local repository. PersonC should not affect how PersonA nor PersonB tracks.


The other way you can push to a differently named branch is to simply tell git push to do so.

git push origin branchA:branchC

This says to push branchA to branchC on the origin remote.

Related