gitconfig global file and tools
Last update
2023-08-18
2023-08-18
« — »
- 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 44 45 46 47 48 | [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 ; show root dir - https://stackoverflow.com/a/957978/13231285 root = rev-parse --show-toplevel [user] name = Alberto Cavalin email = acavalin@users.noreply.github.com [credential "https://github.com"] username = acavalin [core] autocrlf = input safecrlf = true editor = nano excludesfile = ~/.gitignore_global ; https://stackoverflow.com/questions/2293498/applying-a-git-post-commit-hook-to-all-current-and-future-repositories/37293198#37293198 hooksPath = ~/.git-hooks [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:
fish
: see Prompt power-up section on dedicated my fish postbash
: source the git completion scripts in~/.bashrc
:
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 2 3 4 | grep -E --color=always \ --exclude-dir=".git" --exclude-dir="log" --exclude-dir="tmp" \ --exclude="#*#" \ -rin search_term . | less -R |
- Make a single file full backup
1 2 | git bundle create project.bundle --all # backup git clone project.bundle dir # restore |
On the first pull/push saves user/pass in plaintext in ~/.git-credentials.
1 2 | # run this to configure the local repository
git config credential.helper store
|
Source: cache username/pass via StackOverflow and GitHub; dev.to git terminal, side-by-side diff, add CR/LF files