Some tips for git setup and git config

13 Feb 2014

the ssh key

generate ssh key
cd ~/.ssh/
ssh-keygen -t rsa -C "" -f filename

If the options f is not input, the file name of the public/pirvate rsa key pair files will be: id_rsa,

add ssh key
ssh-add ~/.ssh/xxx
list all added ssh key
ssh-add -l
you may run into this error when try ssh-add:

Could not open a connection to your authentication agent.

eval `ssh-agent -s`
add ssh key permanently

Add the key path to ~/.ssh/config

$ vim ~/.ssh/config

IdentityFile ~/.ssh/gitHubKey
IdentityFile ~/.ssh/xxx

git config

global config & repository config

The global setting is stored in ~/.gitconfig

The config of repository is stored in ./.git/config, in the repository directory.

git config --global will use global config, without --global options will use try to use the config file ./git/config in current directory.

config user name & user email for every repository

You may work with multiple repositories, so it is a good practice to config user information for every repository.

# for global setting
git config --global xxx
git config --global

# for repository
git config xxxx
git config
git alias

Setup alias for convenience.

#git st => git status
git config --global 'status'

#git co => git checkout
git config --global 'checkout'

#git lg to view commit log like network graph
git config --global alias.lg "log --all --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%ci) %C(bold blue)<%an>%Creset' --abbrev-commit"

# whatever you like

Follow Me on GitHub

comments powered by Disqus