Date created: 09/13/18 11:44:09. Last modified: 05/17/22 10:09:13



Global Config

Global config in ~/.gitconfig

email = username@domain.tld
name = james
excludesfile = /home/james/.gitignore_global

Global config via CLI:

git config --global "james"
git config --global "username@domain.tld"
git config --global core.excludesfile ~/.gitignore_global



List global config settings:

$git config -l

Disable HTTP SSL certificate validation in the global config file:

$git config --global http.sslverify false
$git config -l


Local Repo Config

Exclude .DS_Store files from repos on a Mac:

echo ".DS_Store
**/._.DS_Store" >> .gitignore  # Add them to the git ignore before committing
git add .gitignore
git commit -m 'gitignore .DS_Store'



Show the changes on unstaged files (files not added with "git add"):

git diff

Show the changes on staged files (files added with "git add"):

git diff --staged

Show the changes on unstaged and staged files:

git diff HEAD

Show the number of lines changes

git diff --stat

Check for merge conflict markers and whitespace errors:

git diff --check


Clone / Commit / Remote

Clone a specific branch:

git clone -b dev


Commit files in an existing directory to an existing git repo (as long as the local files don't overlap with the remote repo):

git init
git remote add origin
git pull origin master
git reset --hard HEAD
git add *
git commit -m "commit to"
git push origin master


Amend a git commit:

git commit --amend
# follow prompts to change the commit message


Rollback to a specific commit ID:

git reset --hard <old-commit-id>
git push -f origin main


Adding a git remote origin:

git remote add origin ssh://login@IP/path/to/repository # Using SSH 
git remote add origin http://IP/path/to/repository # Using HTTP
git push -u origin master


Add a specific branch (e.g. master) from a remote origin:

git remote add --track master origin # Using git
git remote add --track master origin # Using HTTP


Replace a HTTP repo with an SSH one so that SSH keys can be used for authentication:

$ git remote --verbose
origin (fetch)
origin (push)
$ git remote remove origin
$ git remote --verbose
$ git remote add origin
$ git remote --verbose
origin (fetch)
origin (push)


Replace the existing remote origin:

git remote set-url origin


Handy Commands

Create a pretty graph of the git history:

alias gitgraph="git log --all --decorate --oneline --graph"

Previous page: Cisco Watch
Next page: Audio Size