Skip to content

Instantly share code, notes, and snippets.

@unnamedd
Last active March 17, 2025 11:39
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 = [email protected]
signingkey = CD1B6C70016B3BD91C38BC49F94B6756E6B6D57A
[alias]
# Displays the status of your workspace and staging area
st = status
# Commits your staged changes
ci = commit
# Switches branches or restores workspace files
co = checkout
# Manages branches
br = branch
# Displays the list of remote repositories with their URLs
remotes = remote -v
# Displays all branches with their last commit messages
branches = branch -v
# Displays all configured aliases
aliases = "!sh $HOME/.scripts/git-aliases.sh"
# Displays all repository tags
tags = tag -l
# Resets workspace and index to the last commit, discarding all changes
dismiss = reset HEAD --hard
# Undoes the last commit but retains the changes in the workspace and index
rollback = reset soft HEAD~1
# Removes files from the staging area but retains the changes in the workspace
unstage = reset HEAD --
# Discards changes in the workspace
undo = checkout --
# Amends the last commit without altering the commit message
redo = commit --amend --no-edit
# Removes stale references to non-existent remote branches
sane = remote prune origin
# Pushes the current branch to the origin remote
send = "!git push origin $(git rev-parse --abbrev-ref HEAD)"
# Pulls the current branch from the specified remote (defaults to origin if no remote is specified)
update = "!f() { git pull ${1-origin} $(git rev-parse --abbrev-ref HEAD); }; f"
# Updates all sub-directories containing a .git. Should be used in a parent directory.
update-all = "!sh $HOME/.scripts/git-update.sh"
# Synchronizes and updates all submodules recursively
sync = "!git submodule sync --recursive && git submodule update --init --recursive"
# Fetches .gitignore templates from gitignore.io based on specified parameters
gi = "!gi() { curl -L -s https://www.gitignore.io/api/$@; }; gi"
# Displays the commit history as a graph with one line per commit
ll = log --oneline --graph
# Displays the commit history with GPG signature verification
logs = log --show-signature
# Runs lazygit, a terminal UI for git commands
lazy = "! lazygit"
# Runs gitui, another terminal UI for git commands
ui = "! gitui"
# Summarizes repository statistics and information
summary = "! onefetch"
[color]
branch = auto
diff = auto
interactive = auto
status = auto
ui = true
[merge]
tool = opendiff
conflictstyle = diff3
[commit]
gpgsign = true
template = /Users/unnamedd/.stCommitMsg
[gpg]
program = /usr/local/MacGPG2/bin/gpg2
[color "status"]
changed = red normal
untracked = blue normal
added = magenta normal
updated = green normal
branch = yellow normal bold
header = white normal bold
[pager]
blame = delta
# diff = diff-so-fancy | less --tabs=1,5 -RFX
# show = diff-so-fancy | less --tabs=1,5 -RFX
#[url "[email protected]:"]
# insteadOf = https://github.com/
[url "https://github.com/rust-lang/crates.io-index"]
insteadOf = https://github.com/rust-lang/crates.io-index
[init]
defaultBranch = main
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[interactive]
diffFilter = delta --color-only --features=interactive
[diff]
colorMoved = default
[delta]
navigate = true
line-numbers = true
side-by-side = true
hyperlinks = true
[column]
ui = auto
[branch]
sort = -committerdate
[tag]
sort = version:refname
[push]
autoSetupRemote = true
followTags = true
[fetch]
prune = true
pruneTags = true
all = true
[help]
autocorrect = prompt
#!/bin/bash
# Git Update sub folders
# Copyright (c) Thiago Holanda 2024
# https://github.com/unnamedd
# MIT license
# Specify the folder you want to scan
PARENT_DIR="$PWD"
# Loop through each subdirectory in the specified folder
for dir in "$PARENT_DIR"/*/; do
# Check if the subdirectory contains a .git folder
if [ -d "${dir}.git" ]; then
printf "\n###############################################\n\n"
DIR_NAME=$(basename "$dir")
printf "Updating repository \033[0;32m%s\033[0m\n" "$DIR_NAME"
# Change to the subdirectory and handle potential failure
cd "$dir" || {
printf "\033[0;31mFailed to change directory to \033[0;32m%s\033[0;31m\033[0m\n" "$DIR_NAME"
exit 1
}
# Check if exists .target folder, then delete it
if [ -f "Cargo.toml" ]; then
printf "Found a \033[0;31mRust\033[0m project... Cleaning it...\n"
cargo clean
elif [ -f "Package.swift" ]; then
printf "Found a \033[0;35mSwift\033[0m project... Cleaning it...\n"
swift package clean
fi
printf "\n"
# Test if there are changes
if [ -n "$(git status --porcelain)" ]; then
# Stash changes if any
printf "Stashing current changes in: \033[0;32m%s\033[0m...\n" "$DIR_NAME"
git stash push --quiet --include-untracked -m "Auto stash before pull $(date)"
STASHED="true"
else
STASHED="false"
fi
# Pull the latest changes from the repository
git pull --quiet origin "$(git rev-parse --abbrev-ref HEAD)"
# Re-apply the stashed changes if there were any
if [ "$STASHED" = "true" ]; then
printf "Re-applying stash from current changes in: \033[0;32m%s\033[0m...\n" "$DIR_NAME"
git stash pop --quiet
fi
# Go back to the parent directory
cd "$PARENT_DIR" || {
printf "\033[0;31mFailed to change directory to \033[0;32m%s\033[0;31m\033[0m\n" "$PARENT_DIR"
exit 1
}
fi
done
# // 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."[email protected]:".insteadOf "https://github.com/"
# Information about the author/commiter:
# For Personal Repositories
git config --global user.name "Thiago Holanda"
git config --global user.email [email protected]
git config --global user.signingkey CD1B6C70016B3BD91C38BC49F94B6756E6B6D57A
# For EGYM Repositories
git config --local user.name "Thiago Holanda"
git config --local user.email [email protected]
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
# Tags
git config --global tag.sort version:refname
# Branches
git config --global column.ui auto
git config --global branch.sort -committerdate
# Push
git config --global push.autoSetupRemote true
git config --global push.followTags true
# Fetch
git config --global fetch.prune true
git config --global fetch.pruneTags true
# Help
git config --global help.autocorrect prompt
git config --global fetch.all true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment