We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
2018 / 06 / 10
2023 / 06 / 01
Basic Git configuration
Let's customize the git configuration for an improved DX.
Set up our user and email:
git config --global user.name "Your name goes here"
git config --global user.email "your@email.goes.here"
Always git pull
with rebase:
git config --global pull.rebase true
Let’s have colored output for git status
and git diff
:
git config --global color.ui "auto"
Enable the automatic detection of CPU threads to use when packing repositories:
git config --global pack.threads "0"
Here are some very useful aliases.
Let’s add them to our ~/.gitconfig
:
[alias]
l = log --oneline --decorate --graph
ll = log --graph --abbrev-commit --decorate \
--format=format:'%C(yellow)%h%C(reset) %<(14)%C(cyan)%ar%C(reset) \
%C(white)%s%C(reset) %C(bold dim magenta) %an%C(reset) \
%C(bold green)%d%C(reset) %C(brightcyan)%G?%C(reset)'
llb = log --graph --abbrev-commit --decorate \
--format=format:'%C(yellow)%h%C(reset) %<(14)%C(cyan)%ar%C(reset) \
%C(white)%s%C(reset) %C(bold dim magenta) %an%C(reset) \
%C(bold green)%d%C(reset) %C(brightcyan)%G?%C(reset)' --branches
lll = log --graph --abbrev-commit --decorate \
--format=format:'%C(yellow)%h%C(reset) %C(cyan)%ai%C(reset) \
%C(white)%s%C(reset) %C(bold dim magenta) %an%C(reset) \
%C(bold green)%d%C(reset) %C(brightcyan)%G?%C(reset)'
lllb = log --graph --abbrev-commit --decorate \
--format=format:'%C(yellow)%h%C(reset) %C(cyan)%ai%C(reset) \
%C(white)%s%C(reset) %C(bold dim magenta) %an%C(reset) \
%C(bold green)%d%C(reset) %C(brightcyan)%G?%C(reset)' --branches
sl = stash list --format='%gd: %C(bold yellow)%gs'
slp = stash list -p --format='%gd: %C(bold yellow)%gs'
co = checkout
ci = commit
cis = commit -S -s
man = help
h = help
a = add
f = fetch
d = diff
dc = diff --cached
dt = difftool
dtc = difftool --cached
ds = diff --stat
dsc = diff --stat --cached
s = status --short --branch
b = branch
pfl = push --force-with-lease
pp = pull --prune
[credential]
helper = cache
[diff]
algorithm = histogram
Define a global .gitignore file:
git config --global core.excludesfile ~/.gitignore_global
Let’s use it to ignore vscode project files and files generated by the ElixirLS plugin:
echo ".vscode/" >> ~/.gitignore_global
echo ".elixir_ls/" >> ~/.gitignore_global
Set the default branch name for your new repos:
git config --global init.defaultBranch main
Dealing with line endings:
git config --global core.autocrlf input
git config --global core.safecrlf true
Easy peasy, lemon squeezy! :lemon:
Bonus: rebase interactive script
Add a new ~/bin/git-ri
file:
#!/bin/bash
git rebase -i HEAD~$1
Then chmod u+x ~/bin/git-ri
.
And now you can use git ri 2
inside any git
repo instead of typing git rebase -i HEAD~2
whenever you want to squash, rename, etc.
How to delete a remote branch
git push -d origin remote-branch