Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy contents of one branch to other branch?

Tags:

git

git-branch

I have 'develop' and 'InitialPomChanges' branches. I want to copy all the contents of develop branch to InitialPomChanges branch.

like image 476
Balasekhar Nelli Avatar asked Feb 03 '16 10:02

Balasekhar Nelli


People also ask

How do I clone a branch?

In order to clone a specific branch, you have to execute “git branch” with the “-b” and specify the branch you want to clone. $ git clone -b dev https://github.com/username/project.git Cloning into 'project'...


1 Answers

Assuming you want to overwrite all the contents of InitialPomChanges with what is in develop (i.e. you want the contents of InitialPomChanges to exactly match develop), do the following:

git checkout InitialPomChanges git checkout develop .  #copies the contents of develop into the working directory git commit -am "Making InitialPomChanges match develop" 

This will make the last commit in InitialPomChanges match the last commit in develop. To make future merges between the two branches easier, it would be a good idea to now do a git merge develop.

Alternatively, if you want to change the contents of InitialPomChanges and do the merge in one single commit, you can do:

git checkout InitialPomChanges git merge -s theirs develop 
like image 97
David Deutsch Avatar answered Sep 25 '22 17:09

David Deutsch