Git server installation

Install git package on your server (google install git server OS_NAME)

# ssh into your server and run the following commands:

$ sudo adduser git
$ su git
$ mkdir .ssh

#If you haven’t already done so already generate ssh keys on your local client machine:

$ ssh-keygen -t rsa -C “your_email@example.com”

# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
# Enter file in which to save the key (/path_to_your_home_folder/.ssh/id_rsa): [Press enter]…

# copy contents of id_rsa.pub into memory
# back on your server server
$ vi ~/.ssh/authorized_keys
# press letter i and paste (CTRL + V or CMD +V)
# press : (colon) then type wq and enter

# Now it’s time to create some git repo(s) where you’ll push your code:
# Firstly, repo creation on your server:

$cd ~
$ mkdir project.git
$ cd project.git
$ git –bare init

# Back on your client create new git local repo:

$ mkdir project.git
$ cd project.git
$ git init

# Commit your current structure or files you add:

$ git add .
$ git commit -m ‘initial commit’

# add remote repo on your server so local git knows where to push:
$ git remote rm origin
$ git remote add origin git@gitserver:/opt/git/project.git
$ git push origin master

Note: if you are logged in as different user than git on your client you’ll be asked for a password each time you push/fetch/pull from the server. You can set one by running on the server:

#sudo passwd git

Otherwise it should not prompt for any.

Git aliases

Useful git aliases:

#create “cm” alias for “commit”
git config alias.cm commit

#create “co” alias for checkout
git config alias.co checkout

#make “br” alias for branch
git config alias.br branch

# create alias for diff
git config alias.df diff

# create alias for status
git config alias.st diff

# When you want to see just the differences of one function in one file in two different commits:
git config alias.funcdiff ‘!sh -c “git show \”\$1:\$3\” | sed -n \”/^[^ \t].*\$4(/,/^}/p\” > .tmp1 &&
git show \”\$2:\$3\” | sed -n \”/^[^ \t].*\$4(/,/^}/p\” > .tmp2 &&
git diff –no-index .tmp1 .tmp2″‘ –