Git Cheat Sheet

How to publish a repo on a remote location

On the remote server:

git init --bare --shared=group /path/to/repo.git

On the local repo:

git remote add origin ssh://remote_server/path/to/git/repo.git
git push --all origin
git config branch.master.remote origin
git config branch.master.merge refs/heads/master

How to re-attach a detached HEAD

Let’s assume a remote branch was checked out, to put the current head on a branch do:

git checkout -b newbranch

How to delete history for a branch

git checkout --orphan newBranch
git add -A 
git commit
git branch -D master
git branch -m master

At the end you will have to re-connect the master branch to its remote.