DEV Community

classx
classx

Posted on

How to copy commits from one Git repo to another?

Clone basic repo

git clone https://github.com/user1/project1
cd project1
Enter fullscreen mode Exit fullscreen mode

Add external repo

git remote add oldrepo https://github.com/user1/project2
Enter fullscreen mode Exit fullscreen mode

Get the old repo commits

git remote update
Enter fullscreen mode Exit fullscreen mode

examine the whole tree

git log --all --oneline --graph --decorate
Enter fullscreen mode Exit fullscreen mode

Copy (cherry-pick) the commits from the old repo into your new local one

git cherry-pick sha-of-commit-one
git cherry-pick sha-of-commit-two
git cherry-pick sha-of-commit-three
Enter fullscreen mode Exit fullscreen mode

check your local repo is correct

git log
Enter fullscreen mode Exit fullscreen mode

send your new tree (repo state) to github

git push origin master
Enter fullscreen mode Exit fullscreen mode

remove the now-unneeded reference to oldrepo

git remote remove oldrepo
Enter fullscreen mode Exit fullscreen mode

Top comments (0)