Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git move locally committed changes to the new branch and push

Tags:

I am on master. When I do git status I am told

$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 13 commits.
#   (use "git push" to publish your local commits)
#
nothing to commit, working directory clean

So all 13 only exist on my local machine. The problem is that these 13 commits are now supposed to go on a new branch that I should create and push onto the server. I have tried looking at rebase but I am told

$ git rebase origina/master
fatal: Needed a single revision
invalid upstream origina/master

How would I go about pushing these changes into a new branch without messing up the master?

Just to clarify. This is not a duplicate of
moving committed (but not pushed) changes to a new branch this one simply does not work for me no matter what I do.
or
Git: Howto move changes since last commit to a new branch again is of no help.

like image 315
Quillion Avatar asked Jul 02 '13 15:07

Quillion


People also ask

Which command is used to move one commit from one branch to another?

If you want to move commits to an existing branch you need to merge your changes into the existing branch before executing git reset --hard HEAD~3 (see Moving to an existing branch above). If you don't merge your changes first, they will be lost.

Can I copy a commit to another branch?

You can cherry-pick a commit on one branch to create a copy of the commit with the same changes on another branch. If you commit changes to the wrong branch or want to make the same changes to another branch, you can cherry-pick the commit to apply the changes to another branch.


1 Answers

Just do git checkout -b yourbranch and push that.

Then reset master to origin/master.

Order:

git checkout -b mybranch
git push
git checkout master
git reset --hard origin/master
like image 56
Balog Pal Avatar answered Oct 12 '22 11:10

Balog Pal