Reputation: 569
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
:
B
to A
, it shows public/index.html: Permission denied
.I tried to checkout to B
from A
but it's not allowing me. It shows the following message:
error: Your local changes to the following files would be overwritten by checkout:
public/index.html
Please, commit your changes or stash them before you can switch branches.
Aborting
.
How not to lose the code that I wrote in branch B
?
Upvotes: 0
Views: 225
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
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