Last active
January 28, 2025 15:14
-
-
Save mvcds/468c60f457001b9e9d428ea241e5f64d to your computer and use it in GitHub Desktop.
Git Backup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ~/.config/fish/config.fish | |
if status is-interactive | |
# Commands to run in interactive sessions can go here | |
end | |
function setenv; set -gx $argv; end | |
source ~/.env | |
source /opt/homebrew/opt/asdf/libexec/asdf.fish | |
direnv hook fish | source |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#~/.env | |
setenv PATH "$HOME/.gitbin:$PATH" #place git commands on it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[REPO]/.envrc | |
ssh-add --apple-use-keychain | |
git today |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#~/.gitconfig | |
[user] | |
name = Marcos Silva | |
# email = personal email | |
[core] | |
editor = code --wait #might not work at the first time | |
ignorecase = true | |
pager = delta | |
[rerere] | |
enabled = true | |
[diff] | |
renames = copies | |
colorMoved = default | |
[push] | |
default = current | |
autoSetupRemote = true | |
[alias] | |
co = checkout | |
l = log --all --graph --decorate --pretty=format:'%C(yellow)%h %Creset%s %C(green)%ae %C(blue)%ad' --date=relative | |
cm = commit | |
ac = !git add -A && git commit | |
s = status | |
tags = tag -l | |
branches = branch -a | |
remotes = remote -v | |
commend = commit --amend --no-edit | |
up = !git push --set-upstream origin \"$(git rev-parse --abbrev-ref HEAD)\" && git pull | |
purge = clean -fdx -e .env -e .env.* | |
standup = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(green)<%an>%Creset' --abbrev-commit --date=relative --committer='Marcos Vinícius C. da Silva' --all --since='yesterday' | |
[status] | |
showUntrackedFiles = all | |
[clean] | |
requireForce = false | |
[log] | |
date = short | |
follow = true | |
[rebase] | |
autoStash = true | |
[includeIf "gitdir:~/Projects/Work/"] | |
path = .gitconfig-work | |
[url "github-work:work"] | |
insteadOf = [email protected]:work | |
[init] | |
defaultBranch = main | |
[pager] | |
diff = delta | |
log = delta | |
reflog = delta | |
show = delta | |
[delta] | |
plus-style = "syntax #012800" | |
minus-style = "syntax #340001" | |
syntax-theme = Monokai Extended | |
navigate = true | |
line-numbers = true | |
side-by-side = false | |
[interactive] | |
diffFilter = delta --color-only | |
[merge] | |
conflictstyle = diff3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#.ssh/config | |
Host *.github.com | |
AddKeysToAgent yes | |
UseKeychain yes | |
IdentitiesOnly yes | |
Host personal | |
User git | |
HostName github.com | |
IdentityFile ~/.ssh/id_ed25519 | |
Host work | |
User git | |
HostName github.com | |
IdentityFile ~/.ssh/id_ed25519_work |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Get the commit message file | |
COMMIT_MSG_FILE=$1 | |
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE") | |
# Extract branch name | |
BRANCH_NAME=$(git symbolic-ref --short HEAD) | |
# Extract Jira project number (format: PROJECT-NUMBER/DESCRIPTION) | |
if [[ "$BRANCH_NAME" =~ ([A-Z]+-[0-9]+) ]]; then | |
JIRA_TICKET="${BASH_REMATCH[1]}" | |
else | |
JIRA_TICKET="ticketless" | |
fi | |
# Prompt the user for the nature of the change | |
echo "Select the nature of the change:" | |
echo "1) chore" | |
echo "2) fix" | |
echo "3) refactoring" | |
echo "4) doc" | |
echo "5) build" | |
# Read input explicitly from stdin | |
while true; do | |
echo -n "Enter the number corresponding to the nature of the change: " >&2 | |
read -r NATURE_SELECTION </dev/tty | |
case $NATURE_SELECTION in | |
1) | |
NATURE="chore" | |
break | |
;; | |
2) | |
NATURE="fix" | |
break | |
;; | |
3) | |
NATURE="refactoring" | |
break | |
;; | |
4) | |
NATURE="doc" | |
break | |
;; | |
5) | |
NATURE="build" | |
break | |
;; | |
*) | |
echo "Invalid selection. Please try again." >&2 | |
;; | |
esac | |
done | |
# Prepend NATURE and ticket number to the commit message | |
FORMATTED_MSG="$NATURE [$JIRA_TICKET]: $COMMIT_MSG" | |
# Replace the commit message file content with the formatted message | |
echo "$FORMATTED_MSG" > "$COMMIT_MSG_FILE" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BRANCH=${2:-"main"} | |
git checkout $BRANCH | |
git pull origin --no-verify | |
git kill | |
git checkout -b hotfix/$1 | |
git up |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BRANCH=${2:-"main"} | |
git checkout $BRANCH | |
git pull origin --no-verify | |
git kill | |
git checkout -b feature/$1 | |
git up |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git pull | |
git ls-remote --heads $(git remote | head -1) "$branch" | \ | |
cut -d$'\t' -f2 | \ | |
sed 's,refs/heads/,,' | \ | |
grep fix-dealer | |
# https://stackoverflow.com/questions/7726949/remove-tracking-branches-no-longer-on-remote | |
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git checkout --ours . | |
git add . | |
git rebase --skip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BRANCH=${1:-"main"} | |
TIMESTAMP_FILE=".today" #ignore it only for you on .git/info/exclude | |
HOURS_IN_DAY=86400 #24h | |
CURRENT_TIMESTAMP=$(date +%s) | |
update() { | |
git checkout $BRANCH | |
git pull origin | |
git kill | |
git checkout - | |
git merge $BRANCH | |
echo "$1" > "$TIMESTAMP_FILE" | |
} | |
# Check if the timestamp file exists | |
if [ -e "$TIMESTAMP_FILE" ]; then | |
# Get the timestamp of the last execution | |
LAST_EXECUTION_TIMESTAMP=$(cat "$TIMESTAMP_FILE") | |
# Calculate the time difference in seconds | |
time_diff=$((CURRENT_TIMESTAMP - LAST_EXECUTION_TIMESTAMP)) | |
if [ "$time_diff" -ge $HOURS_IN_DAY ]; then | |
update "$CURRENT_TIMESTAMP" | |
fi | |
else | |
update "$CURRENT_TIMESTAMP" | |
fi |
Both standup and bootstrap aliases require minor changes regarding e-mail in the work-related gitconfigs, or use git config --email
(?) on the aliases so not to change them
Now, no aliases require minor changes regarding e-mail in the work-related gitconfigs. Also add some experimental things to see how I like them.
Includes the function to more easily configure the environment variables and the ssh config file
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
standup stollen from @bakotaco