For git i mostly use the git bash on windows. Created some aliases and functions for it, to make my life a little easier. Maybe some of the are helpful for you as well:
alias gpl="git pull"
alias gst="git status"
alias gco="git commit -m "
alias gpu="git push"
alias gbr="git branch"
alias gch="git checkout "
alias gad="git add "
alias gme="git merge "
I think those alias are pretty self explanatory, but if something is unclear just let me know. The part requires a little bit of explanation. Before committing and pushing big changes i like to check each fill. I usually do a git diff on each file and than add it or not. After i have added a file i type git status again, to see the name of the next file.
Wrote the following code to speed this up a little and save me some typing:
#Does a normal git diff, but afterwards it saves the file path
#into a text file. Existing lines get overwritten, so that the file has only
#one line at any time. Has to be called before fadd.
function fdiff {
git diff $1
echo -n $1 > /d/data/fdiff_data.txt
}
#Has to be called after fdiff. Uses the file path fdiff printed
#into a textfile and does a git add one the file. After that it calls
#git status again.
function fadd {
git add $(head -n 1 /d/data/fdiff_data.txt)
git status
}
#Has to be called after fdiff. Rolls back the last file
#compared with fdiff.
function frbl {
toRevert=$(head -n 1 /d/data/fdiff_data.txt)
read -p $"$toRevert Will be reverted! Okay? Yes: return - No: crtl+c"
git checkout -- $toRevert
git status
}
#aliases to shorten the typing even more
alias fa=fadd
alias fd=fdiff
alias fr=frbl
An example for the workflow:
One last function:
#I use this, when i know the commit is very small and unproblematic.
#Usually do a git status before.
function gall {
git add . && git commit -m "$1" && git push
}
Hmmm... looking at the last function has made me think. It would be better if this would abort with an error if i'm about commit more than one file. It should also ask me to confirm if the single file it's about to commit is the file im expecting.
Top comments (0)