Skip to content

Commit

Permalink
Merge pull request #110 from phdru/fixes
Browse files Browse the repository at this point in the history
Fixes and improvements
  • Loading branch information
joelparkerhenderson authored Mar 15, 2024
2 parents 12c40fc + 007b295 commit 7b941c3
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions gitalias.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@

# branch with show description; ideally git will add this feature in the future as `git --show-description`
bsd = "!f(){ \
branch=\"${1:-$(git rev-parse --abbrev-ref HEAD 2>/dev/null)}\"; \
branch=\"${1:-$(git current-branch)}\"; \
git config \"branch.$branch.description\"; \
};f"

Expand Down Expand Up @@ -172,11 +172,11 @@
# cherry-pick - continue the picking process
cpc = cherry-pick --continue

# cherry-pick --no-commit a.k.a. without making a commit
cpn = cherry-pick -n
# cherry-pick -n a.k.a. without making a commit
cpn = cherry-pick --no-commit

# cherry-pick --no-commit a.k.a. without making a commit, and when when recording the commit, append a line that says "(cherry picked from commit ...)"
cpnx = cherry-pick -n -x
# cherry-pick -n a.k.a. without making a commit, and when when recording the commit, append a line that says "(cherry picked from commit ...)"
cpnx = cherry-pick --no-commit -x

### diff aliases ###

Expand All @@ -202,8 +202,8 @@

### grep aliases ###

# grep with -n (--line-number) means show line number
gn = grep -n
# grep -n means show line number
gn = grep --line-number

# Search with our preferred options; a.k.a. `grep-group`
gg = grep-group
Expand Down Expand Up @@ -831,7 +831,7 @@
# summary: print a helpful summary of some typical metrics
summary = "!f() { \
printf \"Summary of this branch...\n\"; \
printf \"%s\n\" \"$(git rev-parse --abbrev-ref HEAD)\"; \
printf \"%s\n\" \"$(git current-branch)\"; \
printf \"%s first commit timestamp\n\" \"$(git log --date-order --format=%cI | tail -1)\"; \
printf \"%s last commit timestamp\n\" \"$(git log -1 --date-order --format=%cI)\"; \
printf \"\nSummary of counts...\n\"; \
Expand All @@ -841,7 +841,7 @@
printf \"%d author count\n\" \"$(git log --format=oneline --format=\"%aE\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}')\"; \
printf \"%d committer count\n\" \"$(git log --format=oneline --format=\"%cE\" | awk '{a[$0]=1}END{for(i in a){n++;} print n}')\"; \
printf \"%d local branch count\n\" \"$(git branch | grep -vc \" -> \")\"; \
printf \"%d remote branch count\n\" \"$(git branch -r | grep -vc \" -> \")\"; \
printf \"%d remote branch count\n\" \"$(git branch --remotes | grep -vc \" -> \")\"; \
printf \"\nSummary of this directory...\n\"; \
printf \"%s\n\" \"$(pwd)\"; \
printf \"%d file count via git ls-files\n\" \"$(git ls-files | wc -l)\"; \
Expand Down Expand Up @@ -1146,7 +1146,7 @@
panic = "!tar cvf ../panic.tar -- *"

# Create an archive file of everything in the repo
archive = "!f() { top=\"$(rev-parse --show-toplevel)\"; cd \"$top\" || exit 1 ; tar cvf \"$top.tar\" \"$top\" ; }; f"
archive = "!f() { top=\"$(git rev-parse --show-toplevel)\"; cd \"$top\" || exit 1 ; tar cvf \"$top.tar\" \"$top\" ; }; f"

# Push with a force and lease, which means that you're pushing in order
# to forcefully overwrite the remote, and you want a safety check first:
Expand Down Expand Up @@ -1183,13 +1183,13 @@
pull1 = "!git pull origin \"$(git current-branch)\""

# Track and untrack, with default parameters, and with printing the command
track = "!f(){ branch=\"$(git rev-parse --abbrev-ref HEAD)\"; cmd=\"git branch $branch -u ${1:-origin}/${2:-$branch}\"; echo \"$cmd\"; $cmd; }; f"
untrack = "!f(){ branch=\"$(git rev-parse --abbrev-ref HEAD)\"; cmd=\"git branch --unset-upstream ${1:-$branch}\"; echo \"$cmd\"; $cmd; }; f"
track = "!f(){ branch=\"$(git current-branch)\"; cmd=\"git branch $branch --set-upstream-to=${1:-origin}/${2:-$branch}\"; echo \"$cmd\"; $cmd; }; f"
untrack = "!f(){ branch=\"$(git current-branch)\"; cmd=\"git branch --unset-upstream ${1:-$branch}\"; echo \"$cmd\"; $cmd; }; f"

# Track all remote branches that aren't already being tracked;
# this is a bit hacky because of the parsing, and we welcome
# better code that works using more-specific git commands.
track-all-remote-branches = "!f() { git branch -r | grep -v ' -> ' | sed 's/^ \\+origin\\///' ; }; f"
track-all-remote-branches = "!f() { git branch --remotes | grep -v ' -> ' | sed 's/^ \\+origin\\///' ; }; f"

### reset-* & undo-* ###

Expand Down Expand Up @@ -1293,7 +1293,7 @@
wip = "!git add --all; git ls-files --deleted -z | xargs -r -0 git rm; git commit --message=wip"

# Restore the deleted files to the working tree.
unwip = "!git log -n 1 | grep -q -c wip && git reset HEAD~1"
unwip = "!git log --max-count=1 | grep -q -c wip && git reset HEAD~1"

# Assume & Unassume
#
Expand Down Expand Up @@ -1329,7 +1329,7 @@
#
assume = update-index --assume-unchanged
unassume = update-index --no-assume-unchanged
assume-all = "!git st -s | awk '{ print $2 }' | xargs -r git assume"
assume-all = "!git status --short | awk '{ print $2 }' | xargs -r git assume"
unassume-all = "!git assumed | xargs -r git update-index --no-assume-unchanged"
assumed = "!git ls-files -v | grep ^h | cut -c 3-"

Expand Down Expand Up @@ -1392,7 +1392,7 @@
#
# Calls the `publish` and `unpublish` aliases.
#
reincarnate = "!f() { [ $# -gt 0 ] && git checkout \"$1\" && git unpublish && git checkout main && git branch -D \"$1\" && git checkout -b \"$1\" && git publish; }; f"
reincarnate = "!f() { [ $# -gt 0 ] && git checkout \"$1\" && git unpublish && git checkout main && git branch --delete --force \"$1\" && git checkout -b \"$1\" && git publish; }; f"

# Friendly wording is easier to remember.
# Thanks to http://gggritso.com/human-git-aliases
Expand All @@ -1416,6 +1416,8 @@

# Show the upstream branch name
upstream-branch = "!git for-each-ref --format='%(upstream:short)' \"$(git symbolic-ref -q HEAD)\""
# Another, shorter and simpler, way
upb = rev-parse --abbrev-ref "@{upstream}"

# Execute shell scripts. Git always runs scripts in the top directory.
# For example "git exec pwd" will always show you the top directory.
Expand Down Expand Up @@ -1647,7 +1649,7 @@
git checkout \"$old_branch\"; \
git pull --ff-only; \
git checkout -b \"$new_branch\" \"$old_branch\"; \
git push -u origin \"$new_branch\"; \
git push --set-upstream origin \"$new_branch\"; \
};f"
# Stop a topic branch; this must be the current branch.
Expand Down Expand Up @@ -1744,7 +1746,7 @@
new_branch=\"$1\"; \
old_branch=\"$(git current-branch)\"; \
git branch --move \"$old_branch\" \"$new_branch\"; \
git push origin \":$old_branch\" \"$new_branch\"; \
git push --set-upstream origin \":$old_branch\" \"$new_branch\"; \
};f"
Expand Down

0 comments on commit 7b941c3

Please sign in to comment.