Made changes in wrong branch - How do I get those changes to a different branch for a commit

Kyle Bridenstine

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
jholtrop

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to undo the changes I made in a git branch?

From Dev

How to revert a commit and create a new branch from those changes?

From Dev

How to tell the last commit of a given git branch merged into another branch to find changes made on the branch?

From Dev

Started from the wrong branch, how do I get my changes into the correct one in a pull request?

From Dev

How do I make my branch like another branch while making the changes as a single commit?

From Java

How to commit my current changes to a different branch in Git

From Dev

How to completely discard changes made on a topic branch

From Dev

How can I create a new remote branch by a commit with no changes?

From Dev

Storing the changes made to a branch, merging the branch, then applying the changes to the main branch

From Dev

How can I git diff local changes to a different branch?

From Java

Git - working on wrong branch - how to copy changes to existing topic branch

From Dev

egit: changes made in one branch are visible on another branch without any commit

From Dev

Git: How do I selectively copy changes from master to branch?

From Dev

How do I insert a commit between two commits on a different branch?

From Java

How to get changes from another branch

From Dev

How to get only changes from branch's branch in git?

From Dev

How do I revert changes in local git branch to remote tracking branch?

From Dev

SVN - How do I only get updated files from server but not commit any local changes I have made?

From Dev

How to commit changes to a branch when head is "* (detached from <tag>)"

From Dev

How to keep inside a branch changes you don't want to commit

From Dev

git: how to add and commit changes to one remote branch but not another?

From Dev

GIT - get changes from branch to master as changes

From Dev

Mercurial, commit changes in working copy to another branch

From Dev

How to get changes from branch pushed to master on local branch as uncommitted changes?

From Dev

How do I get the "changes" (commit message) that triggered a Jenkins build?

From Dev

How do I tell what branch I was on when I stashed changes?

From Dev

How to merge the changes in a branch to the trunk

From Dev

Push changes from my branch to different branch in a different remote

From Dev

Manually compare the main classes of a feature branch and take only those changes or should I merge the main development branch into this feature

Related Related

  1. 1

    How to undo the changes I made in a git branch?

  2. 2

    How to revert a commit and create a new branch from those changes?

  3. 3

    How to tell the last commit of a given git branch merged into another branch to find changes made on the branch?

  4. 4

    Started from the wrong branch, how do I get my changes into the correct one in a pull request?

  5. 5

    How do I make my branch like another branch while making the changes as a single commit?

  6. 6

    How to commit my current changes to a different branch in Git

  7. 7

    How to completely discard changes made on a topic branch

  8. 8

    How can I create a new remote branch by a commit with no changes?

  9. 9

    Storing the changes made to a branch, merging the branch, then applying the changes to the main branch

  10. 10

    How can I git diff local changes to a different branch?

  11. 11

    Git - working on wrong branch - how to copy changes to existing topic branch

  12. 12

    egit: changes made in one branch are visible on another branch without any commit

  13. 13

    Git: How do I selectively copy changes from master to branch?

  14. 14

    How do I insert a commit between two commits on a different branch?

  15. 15

    How to get changes from another branch

  16. 16

    How to get only changes from branch's branch in git?

  17. 17

    How do I revert changes in local git branch to remote tracking branch?

  18. 18

    SVN - How do I only get updated files from server but not commit any local changes I have made?

  19. 19

    How to commit changes to a branch when head is "* (detached from <tag>)"

  20. 20

    How to keep inside a branch changes you don't want to commit

  21. 21

    git: how to add and commit changes to one remote branch but not another?

  22. 22

    GIT - get changes from branch to master as changes

  23. 23

    Mercurial, commit changes in working copy to another branch

  24. 24

    How to get changes from branch pushed to master on local branch as uncommitted changes?

  25. 25

    How do I get the "changes" (commit message) that triggered a Jenkins build?

  26. 26

    How do I tell what branch I was on when I stashed changes?

  27. 27

    How to merge the changes in a branch to the trunk

  28. 28

    Push changes from my branch to different branch in a different remote

  29. 29

    Manually compare the main classes of a feature branch and take only those changes or should I merge the main development branch into this feature

HotTag

Archive