Date created: 09/13/18 11:44:09. Last modified: 06/29/21 12:46:25

Git

http://ohshitgit.com/

 

Global Config

Global config in ~/.gitconfig

[user]
email = username@domain.tld
name = james
[core]
excludesfile = /home/james/.gitignore_global

Global config via CLI:

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

~/.gitignore_gobal:

.DS_Store
._.DS_Store
**/.DS_Store
**/._.DS_Store

List global config settings:

$git config -l
user.email=username@domain.tld
user.name=james
core.excludesfile=~/.gitignore_global

Disable HTTP SSL certificate validation in the global config file:

$git config --global http.sslverify false
$git config -l
user.email=username@domain.tld
user.name=james
core.excludesfile=~/.gitignore_global
http.sslverify=false

 

Local Repo Config

Exclude .DS_Store files from repos on a Mac:

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

 

Clone / Commit / Remote

Clone a specific branch:

git clone -b dev https://github.com/jwbensley/IP-Hashing.git

 

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@github.com:jwbensley/network_graphs.git
git pull origin master
git reset --hard HEAD
git add *
git commit -m "commit to github.com"
git push origin master

 

Amend a git commit:

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

 

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 user@somesite.com:group/project.git # Using git
git remote add --track master origin http://github.com/group/project.git # Using HTTP

 

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

$ git remote --verbose
origin https://github.com/jwbensley/abc123.git (fetch)
origin https://github.com/jwbensley/abc123.git (push)
$ git remote remove origin
$ git remote --verbose
$ git remote add origin git@github.com:jwbensley/abc123.git
$ git remote --verbose
origin git@github.com:jwbensley/abc132.git (fetch)
origin git@github.com:jwbensley/abc123.git (push)

 

Replace the existing remote origin:

git remote set-url origin https://github.com/username/repo

 

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