Skip to content

Instantly share code, notes, and snippets.

@unnamedd
Last active July 17, 2024 10:34
Show Gist options
  • Save unnamedd/2794781 to your computer and use it in GitHub Desktop.
Save unnamedd/2794781 to your computer and use it in GitHub Desktop.
Personal Git Configurations / Git Config
#!/bin/bash
# Define colors
alias_color='\033[1;34m' # Bold blue
comment_color='\033[0;32m' # Green
no_color='\033[0m' # Reset color
printf "\nGit Aliases\n"
# Define the number of spaces for alignment
alignment_spaces=12
# Read the git config file and extract the alias section with comments
awk '
BEGIN { in_alias_section = 0; }
/^\[alias\]/ { in_alias_section = 1; next; }
/^\[/ { in_alias_section = 0; }
in_alias_section { print; }
' ~/.gitconfig | while read -r line; do
# Print the line if it is a comment
if [[ "$line" =~ ^# ]]; then
comment="${line#\# }" # Remove the leading '# ' from the comment
else
# Print the alias command and its comment
if [[ "$line" =~ ^[[:space:]]*([^=[:space:]]+)[[:space:]]*=[[:space:]]*(.*)$ ]]; then
alias_name="${BASH_REMATCH[1]}"
# Calculate the number of spaces needed for alignment
alias_length=${#alias_name}
spaces_needed=$((alignment_spaces - alias_length))
spaces=$(printf "%${spaces_needed}s")
printf "${alias_color}%s${no_color}${spaces}${comment_color}%s${no_color}\n" "$alias_name" "$comment"
comment="" # Reset comment for the next alias
fi
fi
done
[core]
excludesfile = /Users/unnamedd/.gitignore
editor = zed
autocrlf = false
pager = delta
[user]
name = Thiago Holanda
email = unnamedd@gmail.com
signingkey = CD1B6C70016B3BD91C38BC49F94B6756E6B6D57A
[alias]
# Show the current status of your working directory and staging area
st = status
# Commit your staged changes to the repository
ci = commit
# Switch branches or restore working tree files
co = checkout
# List, create, or delete branches
br = branch
# Show the list of remote repositories and their URLs
remotes = remote -v
# List all branches with their last commit messages
branches = branch -v
# List all the aliases you have configured in your Git config file
aliases = "!sh $HOME/.git-aliases.sh"
# List all the tags in the repository
tags = tag -l
# Reset the working directory and the index to the last commit, discarding all changes
dismiss = reset HEAD --hard
# Undo the last commit but keep the changes in the working directory and the index
rollback = reset soft HEAD~1
# Remove files from the staging area while keeping the changes in the working directory
unstage = reset HEAD --
# Discard changes in the working directory
undo = checkout --
# Amend the last commit without changing the commit message
redo = commit --amend --no-edit
# Remove stale references to remote branches that no longer exist
sane = remote prune origin
# Push the current branch to the origin remote
send = "!git push origin $(git rev-parse --abbrev-ref HEAD)"
# Pull the current branch from the specified remote (defaulting to origin if no remote is specified)
update = "!f() { git pull ${1-origin} $(git rev-parse --abbrev-ref HEAD); }; f"
# Synchronize and update all submodules recursively
sync = "!git submodule sync --recursive && git submodule update --init --recursive"
# Fetch .gitignore templates from gitignore.io based on the specified parameters
gi = "!gi() { curl -L -s https://www.gitignore.io/api/$@; }; gi"
# Show the commit history as a graph with one line per commit
ll = log --oneline --graph
# Show the commit history along with GPG signature verification
logs = log --show-signature
# Run lazygit, a terminal UI for git commands
lazy = "! lazygit"
# Run gitui, another terminal UI for git commands
ui = "! gitui"
[color]
branch = auto
diff = auto
interactive = auto
status = auto
ui = true
[merge]
tool = opendiff
# conflictStyle = zdiff3
# Option for Delta
conflictStyle = diff3
[commit]
gpgsign = true
template = /Users/unnamedd/.stCommitMsg
[gpg]
program = /usr/local/MacGPG2/bin/gpg2
[difftool "sourcetree"]
cmd = /usr/local/bin/ksdiff -w \"$LOCAL\" \"$REMOTE\"
path =
[mergetool "sourcetree"]
cmd = /usr/local/bin/ksdiff --merge --output \"$MERGED\" --base \"$BASE\" -- \"$LOCAL\" --snapshot \"$REMOTE\" --snapshot
trustExitCode = true
[color "status"]
changed = red normal
untracked = blue normal
added = magenta normal
updated = green normal
branch = yellow normal bold
header = white normal bold
[pager]
diff = diff-so-fancy | less --tabs=1,5 -RFX
show = diff-so-fancy | less --tabs=1,5 -RFX
#[url "git@github.com:"]
# insteadOf = https://github.com/
[init]
defaultBranch = main
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[submodule]
recurse = true
[interactive]
diffFilter = delta --color-only
[delta]
navigate = true # use n and N to move between diff sections
light = false # set to true if you're in a terminal w/ a light background color (e.g. the default macOS terminal)
[diff]
colorMoved = default
# // reference: http://www.arthurkoziel.com/2008/05/02/git-configuration/
# Git Configuration
# Here are some useful configuration options for Git. Some of them, like the Bash completion, are OS X specific but should also work if you adjust the paths according to your system of choice.
# <Dependencies>
# macOS
brew install git-delta
# Linux
dnf install git-delta
cargo install git-delta # An option in case it isn't that straightforward to install (e.g., Ubuntu).
# </Dependencies>
# Bash completion:
cp /opt/local/etc/bash_completion.d/git ~/.git-bash-completion.sh
echo "[ -f ~/.git-bash-completion.sh ] && . ~/.git-bash-completion.sh" >> ~/.bash_profile
. ~/.bash_profile
# Global ignore file:
echo ".DS_Store" >> ~/.gitignore
git config --global core.excludesfile ~/.gitignore
# Default Branch name
git config --global init.defaultBranch main
# Shortcuts for often used commands:
git config --global alias.st status -sb
git config --global alias.ci commit
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.remotes remote -v
git config --global alias.branches branch -v
git config --global alias.tags tag -l
git config --global alias.dismiss "reset HEAD --hard"
git config --global alias.rollback "reset --soft HEAD~1"
git config --global alias.unstage "reset HEAD --"
git config --global alias.undo "checkout --"
git config --global alias.redo "commit --amend --no-edit"
git config --global alias.sane "remote prune origin"
git config --global alias.sync "!git submodule sync --recursive && git submodule update --init --recursive"
git config --global alias.send "!git push origin $(git rev-parse --abbrev-ref HEAD)" # Don't run this line directly on Terminal
git config --global alias.update "!git pull origin $(git rev-parse --abbrev-ref HEAD)" # Don't run this line directly on Terminal
git config --global alias.gi '!gi() { curl -L -s https://www.gitignore.io/api/$@; }; gi'
git config --global alias.ll "log --oneline --graph"
git config --global alias.logs "log --show-signature"
git config --global url."git@github.com:".insteadOf "https://github.com/"
# Information about the author/commiter:
# For Personal Repositories
git config --global user.name "Thiago Holanda"
git config --global user.email unnamedd@gmail.com
git config --global user.signingkey CD1B6C70016B3BD91C38BC49F94B6756E6B6D57A
# For EGYM Repositories
git config --local user.name "Thiago Holanda"
git config --local user.email thiago.holanda@egym.com
git config --local user.signingkey B3B47A9D5F56A3DF533CD3242DF0E2381DE894F3
# Colorized output:
git config --global color.ui true
git config --global color.diff auto
git config --global color.interactive auto
git config --global color.branch auto
git config --global color.status auto
git config --global color.status.changed "red normal"
git config --global color.status.untracked "blue normal"
git config --global color.status.added "magenta normal"
git config --global color.status.updated "green normal"
git config --global color.status.branch "yellow normal bold"
git config --global color.status.header "white normal bold"
# TextMate as the default editor:
git config --global core.editor "code"
# Opendiff (FileMerge) to resolve merge conflicts:
git config --global merge.tool opendiff
git config --global merge.conflictStyle zdiff3
# Signing commits
git config --global commit.gpgsign true
git config --local commit.gpgsign true
# Submodules
git config --global submodule.recurse true
# Change the font in gitk: Open ~/.gitk and add:
set mainfont {Monaco 12}
set textfont {Monaco 12}
set uifont {Monaco 12}
# Delta Settings
git config --global color.branch auto
git config --global core.pager delta
git config --global interactive.diffFilter delta --color-only
git config --global delta.navigate true
git config --global merge.conflictstyle diff3
git config --global diff.colorMoved default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment