user3279058
user3279058

Reputation: 569

How to push branch to remote

I have 2 branches in my local system named A and B. I checkout to B means now I am in B. I wrote some code, commited in that branch itself but I didn't push the branch to remote. Now I checkout to A, where I am facing some problems so I want to push B to remote.

Is it possible to push from a branch to another branch?

I am facing this problems in Branch A:

How not to lose the code that I wrote in branch B?

Upvotes: 0

Views: 225

Answers (3)

abnvp
abnvp

Reputation: 1027

Before moving on to any other branch, you can either temporarily save them to be able to restore them later ( read stash them ) or commit the changes for that particular branch.

Your changes will always be safe if you have done any of the above.

I think, here you would want to stash your changes instead of pushing the branch B's changes to the remote.

"git stash" is the command for saving all the changes temporarily. You can restore these changes on any branch.

Upvotes: 0

Michael Durrant
Michael Durrant

Reputation: 96594

Do git push origin the_other_branch_name

It's ok to do it while you working are in another branch with either unstaged or staged files (I just tried it).

Upvotes: 0

Agis
Agis

Reputation: 33656

Do this:

$ git push origin B:refs/heads/B

Upvotes: 1

Related Questions