Just some notes. Recently, I had to merge and organize 3 repositories as one, so here are the things I ended up doing.
Merging 2 repositories in to one with full history
cd path/to/project-b git remote add project-a path/to/project-a git fetch project-a git merge project-a/master # or whichever branch you want to merge
In my case, the local repository (source) was project-a, and the public repository (destination) was project-b.
When I was finished merging, instead of
git push -u I had to push it like so:
git push --set-upstream origin master
(where master was the branch I was targeting)
Accepting all merged changes
After doing the above, my repository was filled with conflicts. I didn’t care about the the remote changes, so I was able to just blanket accept my local changes.
git checkout --ours -- <paths> # or git checkout --theirs -- <paths>
In the above context, project-b (destination) is
--ours, and project-a is
--theirs. I used
--theirs, as I wanted my local repository merged in to the public one.
Adding an empty branch
git checkout --orphan NEW_BRANCH_NAME git rm -rf .
Now add/commit any change to keep it.
Adding Multiple Origins
I haven’t done this yet, but eventually I’ll need to push code in to two separate repositories on demand.
Reverting a commit
Say you make a bad commit. You can revert the changes like so.
git revert --no-commit 0766c053..HEAD git commit
Just look-up the version ID of the commit you want instead, and edit it in to the above command.
To discard a change, re-checkout the file.
git checkout path/to/file/to/revert
For ‘all unstaged files’ (everything??).
git checkout -- .