chipbk10
chipbk10

Reputation: 5955

how to git push to a local branch?

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

Upvotes: 12

Views: 36544

Answers (4)

Veer
Veer

Reputation: 166

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)

Upvotes: 0

user185953
user185953

Reputation: 81

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.

Upvotes: 2

ElpieKay
ElpieKay

Reputation: 30858

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.

Upvotes: 21

Dennis Kotsch
Dennis Kotsch

Reputation: 184

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

Upvotes: 2

Related Questions