Skip to content

Instantly share code, notes, and snippets.

@danjenson
Created October 19, 2022 02:08
Show Gist options
  • Save danjenson/31d5ad35af474e0506eb888cdaf574c4 to your computer and use it in GitHub Desktop.
Save danjenson/31d5ad35af474e0506eb888cdaf574c4 to your computer and use it in GitHub Desktop.
A collection of simple git functions
#!/bin/bash
# source this file from your ~/.bashrc, i.e. `source git_funcs.sh`
# run this before making changes, otherwise you'll need to deal with merge conflicts
# usage: gitu
gitu () { git pull --rebase; }
# add it all, push it all, fuck the police
# usage: gitx
gitx () {
git add --all
git commit -m ${1:-yolo}
git push
}
# switch to a git branch
# usage: gitb feature_a
gitb () { git checkout $1; }
# rename a file
# usage: gitrn my_file_a.tsv my_file_b.tsv
gitrn () { git mv $1 $2; }
# get the git state of your current project
# usage: gits
gits () { git status; }
# remove a file
# usage: gitrm my_file
gitrm () { git rm -f $1; }
# create a git branch
# usage: gitcb
gitcb () { git checkout -b $1 && git push --set-upstream origin $1; }
# delete branch
# usage: gitdb branch_name
gitdb () { git branch -d $1 && git push origin --delete $1; }
# merge branch into current branch
# usage: gitm other_branch_name
gitm () { git merge --squash $1; }
# git history (as patches)
# usage: gith path/to/some_file
gith () { git log -p -- $1; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment