Reputation: 2227
Currently I'm working on the master and made some changes. Instead of just push my current working I wanted to push all the things to a branch (Cause several people are working on the same thing, don't want to make a fuss). So following is what I did:
git branch <branch_name>
git push origin <branch_name>
git checkout <branch_name>
What should i do to add the current master changes to the branch? (And leave the master unchanged!!!)
Upvotes: 1
Views: 2968
Reputation: 40041
If you have already committed changes to your master (by misstake) which should go to a branch instead I see two alternatives.
In this case you can just create branch from your current master git checkout -b some_new_branch
and push that git push origin HEAD:some_new_branch
and so creating a new remote branch for others to work in.
After doing that you need to move your local copy of master back to where it should be (ie before any local changes where commited) git checkout master; git reset --hard origin/master
.
In this case you first need to checkout the branch git checkout some_old_branch
and then cherry-pick or possibly merge all changes from master that where committed there by misstake. To find them you do git log
in master and write down all hashes for the commits, then for each you do git cherry-pick <some commit>
into the branch. After that you basically do the same as alternative one, push from the branch and reset your master.
Upvotes: 2
Reputation: 33844
Specifically, you should do this:
$ git checkout master # start on the master branch
$ git checkout -b new-branch # this will create a new branch that is a duplicate of master
$ git push origin new-branch # this will push your new branch to your git repo
$ git checkout master # you are now back on master, which is the same as you left it!
Upvotes: 0
Reputation: 2650
Since you are in master branch and all your current changes are in master branch , you need to the following steps.
resolve any conflits
Upvotes: 1
Reputation: 535717
What should i do to add the current master changes to the branch
It is not clear what the phrase "the current master changes" is supposed to mean.
If you mean unstaged, uncommitted changes in the working copy, just add and commit. You are now on the branch (because you checked it out), so the new commit will be on the branch.
If you mean you made some commits on the master that you wish were on the branch and not on the master, then (since you have already created a branch from the last commit) check out master and reset --hard
back to the last commit that you want to leave on the master. Then check out the branch again and resume working.
By the way, this part of your move is a bit odd:
git push origin <branch_name>
That does "make a fuss", since now the remote repo contains a branch that you presumably intended for your private work in progress.
Upvotes: 0
Reputation: 27305
If you haven't commited the changes make a new branch and change to the branch. Your current changes will be available in the new branch and you can commit them in the new branch.
git branch new_branch_name
git checkout new_branch_name
If you have already commited your changes in the master branch make a new branch from master and revert/reset your master branch to the last origin state.
Upvotes: 1