Move some git to a new repo

I use this rest-more , which contains many web-api implementations (e.g. Facebook or Linkedin). I forked this repository and in my branch I added my own implementation of another web api.

However, now I find it rather difficult to constantly update the original repository. I reinstall my branch every time the original repository changes, which is pretty tedious. So I want to split my own implementation into a standalone repository.

All my commits in my branch are merged together. Only one commit per file from the source repository.

Is there an easy way to move my commits to a new repository? I want to do this in order to preserve commit history.

0
source share
4 answers

First I open a new repository:

git init new-repo 

Then I moved my branch to this repository:

 cd rest-more git push ../new-repo/ my_branch cd ../new-repo git co my_branch 

I created a new empty initial commit:

 git checkout --orphan newroot git commit --allow-empty -m 'root commit' 

Then I reset my branch to this starting point using the interactive flag to select only my commits:

 git rebase --onto newroot --root my_branch -i 

Conflicts need to be resolved along this path, and finally, I only get the repository with my commits.

(There may be improvements. Feel free to suggest something.)

0
source

The easiest: just stop accepting updates from the source repository. Remove the remote repository from the .git / config file.

Otherwise, from my notes:

Suppose you want to move dir1 from repository A to repository B :

Clone repository A. To be safe, we break the connection between clone and A to make sure that none of our changes are accidentally sent back.

 git clone git://git.foo.com/ProjectA.git NewProject cd NewProject git remote rm origin 

Delete everything except dir1 .

 git filter-branch --subdirectory-filter dir1 

This will make dir1 a new root, which you can undo:

 mkdir dir1 mv * dir1 git commit -a 

Now merge this repository into repository B

 git clone git://git.foo.com/ProjectB.git ProjectB cd ProjectB git remote add repo-A-branch ~/NewProject git pull repo-A-branch master git remote rm repo-A-branch 
+1
source

I would recommend storing one repository and creating a second branch for your changes . You can then select your cherry commit to this new branch to isolate your changes and merge / your changes into the third branch to create releases of your code. Saving it in one repository greatly simplifies synchronization with upstream development, and making changes to their own branch allows isolating them. The third branch can serve as "your changes applied to the branch upstream."

+1
source

Assuming you have a strictly linear history of your commits (without merges), you can simply export all your commits as follows:

 git format-patch <start>..<stop> 

Where start and stop are the range of commits required ( start is the commit you started with, and stop is probably the current HEAD ).

This will create many files named NNNNN-commit-description.patch , NNNNN is the number starting with 00001.

Then create a new empty repository and import these patches:

 git init newrepo cd newrepo find <oldrepo>/*.patch | xargs git am 

In addition, instead of launching an empty repo, you can first commit to some source files that you depend on so that all of your fixes can be applied cleanly.

+1
source

All Articles