Git Notes on Combining Repositories

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

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:

(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.

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

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.


Just look-up the version ID of the commit you want instead, and edit it in to the above command.

Discarding changes

To discard a change, re-checkout the file.


For ‘all unstaged files’ (everything??).