Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy last commits from master to branch

Tags:

git

Present situation in the picture. Green branch is a master. How to copy last 3 commits from master to pink branch, but without touching a master ?

enter image description here

like image 585
marioosh Avatar asked Oct 22 '12 06:10

marioosh


2 Answers

git checkout <name of pink branch>
git merge master

will do exactly what you want (merge the 3 commits from master into the pink branch, but leave master itself where it is).

like image 56
Amber Avatar answered Nov 17 '22 23:11

Amber


If you mean you wished you had waited to branch (and it's a personal project branch) you can (from branch "pink") use git rebase master. That will pop off the pink commits, move pink ahead to 29934b6 and then re-apply the patches.

Otherwise Amber's git merge is probably the best answer.

Another possibility is (again, from "pink") git cherry-pick 9a51fd2; ... for each of those changes. That will make individual new commits on pink. You can also name the branches as master, master^ and master^^.

like image 10
Ben Jackson Avatar answered Nov 18 '22 00:11

Ben Jackson