clean up git

git reflog expire --expire=1.minute refs/heads/master
git fsck --unreachable
git prune
git gc
git maintenance run

A simple way to create git repository on a server machine connecting via ssh

Create a working copy repository

First, create a new local git repository and add all files within this folder.

cd ˜/workshop
git init
git add .
git commit -m "initial repository creation"

Create the bare repository

Then we have to create a bare repository on the server side. Let’s assume the user ralfwehner is the repository admin user on server side. For this step i will show two alternative ways:

a) We clone the server’s repositiory on the client machine and copy it via scp up to the server:

git clone --bare .git ../workshop.git
scp -r ../workshop.git ralfwehner@localhost:/Users/ralfwehner/gitrepos/workspace.git

b) We create a new empty repository on the server side and copy the developer’s repository from client machine to server (recommended when using difference git versions on server and clients): So, first create the bare repository on server side:

sudo -u ralfwehner mkdir -m 770 /Users/ralfwehner/gitrepos/workshop.git
cd /Users/ralfwehner/gitrepos/workshop.git
sudo -u ralfwehner git --bare init --shared=group

From client side the developer’s project must be pushed into the new bare server repository:

git remote add origin ssh://ralfwehner@dev-server/Users/ralfwehner/gitrepos/workshop.git
git push origin master

That’s it. The project ‘workshop’ is now available on the server and can be cloned using the git clone command. E.g.:

cd /tmp/
git clone ralfwehner@localhost:/Users/ralfwehner/gitrepos/workshop.git myclonedworkshop


Manipulate origin/HEAD

How to remove origin/HEAD?

git update-ref -d refs/remotes/origin/HEAD

How to create origin/HEAD?

git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/master


Update Git submodule to latest commit on origin

In your project parent directory, run:

git submodule update --init --recursive --remote