Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move the current working branch to master branch in git

Tags:

git

I have currently one of the project it contain more branches. master branch not yet merger long time. So i want switched to master with latest code.

Can you please give me necessary commands and steps.

Let me re-frame my question.

I am working in a project with different branches. The latest changes were in some branch other than master. Now my requirement is: is there a way to move the current working branch to master without merging it with master, to avoid conflicts?

like image 300
user857574 Avatar asked Aug 23 '11 13:08

user857574


People also ask

How do I move a branch to a master?

The git branch command can be used to create a new branch. When you want to start a new feature, you create a new branch off main using git branch new_branch . Once created you can then use git checkout new_branch to switch to that branch.


1 Answers

If you want to have in master exactly the same files state as in other_branch and save history - do the following (and note the period at the end):

git checkout master git checkout other_branch . 

Now you will have a full copy of other_branch in current master (it is softer than reset), not yet committed. Then make a regular commit:

git add --all git commit -m "* copy other_branch to master working tree" 

Note: untracked (unindexed) files (directories) from other_branch will remain, if they are not tracked by master. To remove those untracked files (directories):

git clean -fd 

See How to remove local (untracked) files from the current Git working tree? for more details.

like image 105
radistao Avatar answered Sep 24 '22 15:09

radistao