Skip to content

Instantly share code, notes, and snippets.

@shadow-fox
Created August 13, 2014 21:54
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save shadow-fox/fcbd82c5e072659bed8e to your computer and use it in GitHub Desktop.
How to: GIT: The parent of the root commit on one repository is the latest commit on the other. It is by awesome guidance from kevin known as _ikke_ in #git irc channel.
1. First clone both the repos. both repos live under their respective dir, project1 and project2. and they have their own .git dir.
cd parentdir
parentdir.
|-- project1
| |-- app
| `-- .git
`-- project2
|-- app
`-- .git
2. Add project2 to project1 as a remote. If you want to project2 should be appended to project1. e.g project1 commits + project2 commits
cd project1
git remote add project2 path/to/project2/.git
3. git fetch project2
4. Both repos have a branch called master. (In my case it was).
5. git rev-list project2/master | tail -n1
that should give you the hash of the first commit
6. git show <hash>
to confirm
7. git rev-parse master
get the hash of the last commit on the master branch
8. git show <hash>
to confirm
9. echo "<root_hash> <master_hash>" >> .git/info/grafts
where root_hash is the hash from step 5.
and master_hash is from step 7
10. git log root_hash --oneline
You should see project1's all commit + the first commit hash from project2
So in a way there would be count(project1's commit)+1 number of commits
11. git filter-branch project2/master
To make the link permanent
12. git checkout -B master project2/master
to reset master to the latest commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment