Reputation: 6373
I just made some changes to my code thinking that I was in my branch fooBar. It turns out I was working on master. I'm not allowed to commit my code to master. I must push my code to the fooBar branch, put in a pull-request to the higher ups, and then they will merge my branch to the master.
So my dilemma is that I made these changes on master locally. When I do git checkout fooBar
my code changes do not come with me to the branch. I've tried pushing these changes to the branch by doing git push origin fooBar
but it just says "Everything Up-To-Date" even though the changes didn't get to the branch.
How can I get my changes pushed to the fooBar branch?
$ git status
On branch master
Upvotes: 2
Views: 1488
Reputation: 406
If your changes on master are ahead of the remote fooBar branch and you just want to push them to the remote fooBar branch, then you can do:
git push origin master:fooBar
Alternatively you can pull the changes into your local fooBar branch using a merge/cherry-pick/etc...
For example:
git checkout fooBar
# To pull in the last commit from master into fooBar:
git cherry-pick master
# Or to pull in all commits on master into fooBar:
git merge master
Then just push your local fooBar branch like normal.
Upvotes: 3
Reputation: 99
I would copy the code you committed to master first (every file) Then rollback master to the previous commit. Next I would go to the fooBar branch, and check out every file that was supposed to be committed there. Make your changes to those files. Then commit those changes to the fooBar branch.
I hope that makes sense.
Upvotes: 0