12

I git clone a project on my computer and have a local master branch, let say A. Here, I create some local branches (let say B and C).

I made some changes in B and C. So, how do I can git push to merge the changes in B and C to A?

Normally, I see that

 git push origin master 
to push to the remote repository, but I want to push to a local branch.

Thanks

chipbk10
  • 5,783
  • 12
  • 49
  • 85

4 Answers4

20

Use git merge instead to manipulate local branches.

git checkout master
git merge B
git merge C

If you really want to push a local branch to another local branch, git push . B:master, though this is quite rare.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
2

While on the master branch, have you tried

git merge B

This should merge your local branch B back into master, same can be done for branch C

https://git-scm.com/docs/git-merge

Dennis Kotsch
  • 184
  • 3
  • 5
2

As others said, normally you want to switch to A and then merge from B instead.

However, if you do it regularly, in some edge cases it makes sense to set A as upstream branch for B

git checkout B
git branch --set-upstream-to A
# shorthand: git branch -u A

and then use git push from branch B like you asked.

user185953
  • 83
  • 1
  • 6
0

If You want to merge branch A to B

First commit your changes, if you have done any changes and want that changes to be merged to B branch

git add --file path-- : adds files to stage and then

git commit -m "add commit msg"

and then git checkout B, you will be now in B branch.

git merge --no-ff A (we are doing non fast forward merge, merging branch A into B branch)

gonidelis
  • 885
  • 10
  • 32
Veer
  • 166
  • 1
  • 1
  • 16