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)

Source: http://stackoverflow.com/a/10548919

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.

Source: http://stackoverflow.com/a/16826016

Adding an empty branch

git checkout --orphan NEW_BRANCH_NAME
git rm -rf .

Now add/commit any change to keep it.

Source: http://bitflop.com/tutorials/how-to-create-a-new-and-empty-branch-in-git.html

Adding Multiple Origins

I haven’t done this yet, but eventually I’ll need to push code in to two separate repositories on demand.

Details: http://stackoverflow.com/a/11690868

Reverting a commit

Say you make a bad commit. You can revert the changes like so.

git revert --no-commit 0766c053..HEAD
git commit

Source: http://stackoverflow.com/a/21718540

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.

git checkout path/to/file/to/revert

Source: http://stackoverflow.com/a/52713

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

git checkout -- .