gitconfig global file and tools
mouse 505 · person cloud · link
Last update
2019-02-27
2019
02-27
« — »
  • Setup a main config file in /etc/gitconfig or ~/.gitconfig:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  df = diff --staged
  cp = cherry-pick
  bd  = branch --edit-description
  bds = !GIT_EDITOR=cat git branch --edit-description | grep -v "^#"
  pom = push origin master
  lom = pull origin master
  poa = push origin alb
  loa = pull origin alb
  lst = ls-tree --full-tree -r HEAD
  hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --date=short
  histg = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
  undoci = reset --soft HEAD^
  redoci = commit -c ORIG_HEAD
  stash-unapply = !git stash show -p | git apply -R
  stash-diff = stash show -p
  ; drop all local commits and align with origin/master
  reset-om = reset --hard origin/master
  ; side-by-side diff commands (install ydiff command)
  dfs   = !git diff  --staged | ydiff -s -w 0 -t 2 --wrap
  diffs = !git diff           | ydiff -s -w 0 -t 2 --wrap

[user]
  name  = Alberto Cavalin
  email = acavalin@users.noreply.github.com

[credential "https://github.com"]
  username = acavalin

[core]
  autocrlf = input
  safecrlf = true
  excludesfile = ~/.gitignore_global

[push]
  default = current

[color]
  ui = true
  • Enable adding CR/LF files
1
2
git config --global core.autocrlf false
git config --global core.safecrlf false

resulting in this ~/.gitconfig:

1
2
3
[core]
  autocrlf = false
  safecrlf = false
  • Setup the ignore list in ~/.gitignore_global:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# jEdit temporary files
*.marks
\#Untitled-*#

# Rails files (db, log, temp, cfg)
/db/*.sqlite3
/db/*.sqlite3-journal
/log/*.log
/log/*.gz
/tmp
Gemfile.lock
/config/database.yml

.DS_Store
nohup.out
  • Use a side-by-side colored diff tool

  • Enhance the terminal experience:

    1
    2
    3
    [ -f "$HOME/.git-completion.bash" ] && source "$HOME/.git-completion.bash"
    [ -f "$HOME/.git-prompt.sh" ] && source "$HOME/.git-prompt.sh"
    export PROMPT_COMMAND='__git_ps1'
    
  • Install some good interfaces for git:

1
2
apt-get install tig  # ncurses-based text-mode interface
apt-get install gitg # gtk visual repository viewer
  • Look for a file in a project:
1
grep --color=always --exclude-dir=".git" -rin term . | less -R

Source: cache username/pass via StackOverflow and GitHub; dev.to git terminal, side-by-side diff, add CR/LF files

See also: When to Use Git Reset, Git Revert & Git Checkout