-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-aliases.sh
81 lines (70 loc) · 2.74 KB
/
git-aliases.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# See also: shell-aliases.sh
alias gs='git status'
alias gl='git log --oneline --graph'
alias gll='git log --stat --patch'
alias gd='git diff'
# Use this to stage changes
alias gap='git add --patch'
# Use this to stage new files
alias ga='git add'
# This shows what you have staged so far
alias gdc='git diff --cached'
alias gc='git commit'
# Change the commit message
alias gca='git commit --amend'
# Add changes to the last commit, without editing the message
alias gcane='git commit --amend --no-edit'
alias gb='git branch -v'
alias gbr='git branch -v --remote'
# List branches sorted by date (useful to see the most recent local or remote branches)
alias gbd='git for-each-ref --sort=committerdate $target --format="%(refname:short)$(echo -e \"\\t\")%(committerdate:relative) (%(authorname)) %(subject)" | column -t -s "$(echo -e \"\\t\")"'
alias gbdr='gbd -r'
alias gco='git checkout'
alias gfo='git fetch origin'
alias gfa='git fetch --all'
alias gmom='git merge origin/master'
alias gmod='git merge origin/develop'
alias grom='git rebase --autostash origin/master'
alias grod='git rebase --autostash origin/develop'
alias gmu='git merge @{upstream}'
alias gru='git rebase --autostash @{upstream}'
alias gri='git rebase --interactive'
alias grc='git rebase --continue'
alias gra='git rebase --abort'
alias gcp='git cherry-pick'
alias gss='git stash save'
alias gsp='git stash pop'
# For stashing away some unwanted changes, but keeping the rest
# Only stashes those lines you say 'y' to (remove them for now, pop them back later)
alias gssp='git stash --patch'
# Remove ("kill") whatever lines you say 'y' to (stashes what you select, then drops the stash)
alias gssk='git stash --patch && git stash drop'
# This is safer than `git reset --hard` because if you did accidentally kill
# something you wanted, recovery is possible from `git reflog`
# Fixup a past commit. This will amend the given commit with whatever you have staged.
#
# For example, to stage some changes and add them to the commit two places before the latest commit.
#
# git add -p
#
# git log --oneline
#
# gcf HEAD~~
#
git_commit_immediate_fixup() {
local commit_to_amend="$1"
if [ -z "$commit_to_amend" ]
then
echo "You must provide a commit to fixup!"
return
fi
# We need a static commit ref in case the commit is something relative like HEAD~
commit_to_amend="$(git rev-parse "${commit_to_amend}")" || return
echo ">> Committing"
git commit --no-verify --fixup "${commit_to_amend}" || return
echo ">> Performing rebase"
# --autosquash requires -i, but we can avoid interaction with a dummy EDITOR
EDITOR=true git rebase --interactive --autosquash --autostash \
--preserve-merges "${commit_to_amend}~"
}
alias gcf='git_commit_immediate_fixup'