Add branch-agnostic git aliases
This commit is contained in:
parent
82649dc92d
commit
c71e7f6634
28
.gitattributes
vendored
Normal file
28
.gitattributes
vendored
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
*.c diff=cpp
|
||||||
|
*.h diff=cpp
|
||||||
|
*.c++ diff=cpp
|
||||||
|
*.h++ diff=cpp
|
||||||
|
*.cpp diff=cpp
|
||||||
|
*.hpp diff=cpp
|
||||||
|
*.cc diff=cpp
|
||||||
|
*.hh diff=cpp
|
||||||
|
*.m diff=objc
|
||||||
|
*.mm diff=objc
|
||||||
|
*.cs diff=csharp
|
||||||
|
*.css diff=css
|
||||||
|
*.html diff=html
|
||||||
|
*.xhtml diff=html
|
||||||
|
*.js diff=javascript
|
||||||
|
*.ts diff=javascript
|
||||||
|
*.ex diff=elixir
|
||||||
|
*.exs diff=elixir
|
||||||
|
*.go diff=golang
|
||||||
|
*.php diff=php
|
||||||
|
*.pl diff=perl
|
||||||
|
*.py diff=python
|
||||||
|
*.md diff=markdown
|
||||||
|
*.rb diff=ruby
|
||||||
|
*.rake diff=ruby
|
||||||
|
*.rs diff=rust
|
||||||
|
*.lisp diff=lisp
|
||||||
|
*.el diff=lisp
|
10
.gitconfig
10
.gitconfig
@ -12,7 +12,6 @@
|
|||||||
untracked = 32 # Brighter blue
|
untracked = 32 # Brighter blue
|
||||||
|
|
||||||
[alias]
|
[alias]
|
||||||
bv = branch -vv
|
|
||||||
co = checkout
|
co = checkout
|
||||||
amend = commit --amend
|
amend = commit --amend
|
||||||
aq = commit --amend --no-edit
|
aq = commit --amend --no-edit
|
||||||
@ -27,6 +26,14 @@
|
|||||||
fi >/dev/null 2>&1; git rebase --autosquash -i \"${r}\"; }; f"
|
fi >/dev/null 2>&1; git rebase --autosquash -i \"${r}\"; }; f"
|
||||||
patch = !git --no-pager diff --no-color
|
patch = !git --no-pager diff --no-color
|
||||||
diff = diff-so-fancy | less --tabs=4 -RFXS --pattern '^(Date|added|deleted|modified): '
|
diff = diff-so-fancy | less --tabs=4 -RFXS --pattern '^(Date|added|deleted|modified): '
|
||||||
|
review = "!f(){ BRANCH=\"$(git rev-parse --abbrev-ref HEAD)\"; git push -u origin \"$BRANCH\":user/$USER/\"$BRANCH\" --force; }; f"
|
||||||
|
|
||||||
|
# Branch-agnostic aliases
|
||||||
|
# https://aj.codes/post/branch-agnostic-git-aliases/
|
||||||
|
default-branch = "!git symbolic-ref refs/remotes/origin/HEAD | cut -f4 -d/"
|
||||||
|
pom = push origin $(git default-branch)
|
||||||
|
merged-branches = "!git branch --merged $(git default-branch)"
|
||||||
|
sync = "!git fetch -p && git rebase origin/$(git default-branch)"
|
||||||
|
|
||||||
[push]
|
[push]
|
||||||
default = simple
|
default = simple
|
||||||
@ -35,6 +42,7 @@
|
|||||||
editor = vim
|
editor = vim
|
||||||
excludesfile = /home/tgrosinger/.gitignore_global
|
excludesfile = /home/tgrosinger/.gitignore_global
|
||||||
pager = diff-so-fancy | less --tabs=4 -RFX
|
pager = diff-so-fancy | less --tabs=4 -RFX
|
||||||
|
attributesfile = /home/tgrosinger/.gitattributes
|
||||||
|
|
||||||
[diff]
|
[diff]
|
||||||
tool = meld
|
tool = meld
|
||||||
|
@ -86,6 +86,7 @@ function performSetup() {
|
|||||||
|
|
||||||
echo "Linking Git..."
|
echo "Linking Git..."
|
||||||
linkFile ".gitconfig"
|
linkFile ".gitconfig"
|
||||||
|
linkFile ".gitattributes"
|
||||||
|
|
||||||
echo "Linking tmux..."
|
echo "Linking tmux..."
|
||||||
linkFile ".tmux.conf"
|
linkFile ".tmux.conf"
|
||||||
|
@ -11,9 +11,10 @@
|
|||||||
# Summary
|
# Summary
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Performs a safe deletion of a branch by pulling master from origin, then
|
# Performs a safe deletion of a branch by pulling the default branch from
|
||||||
# rebasing the specified or current branch on master. Once complete, a branch
|
# origin, then rebasing the specified or current branch on the default branch.
|
||||||
# deletion is attempted, however aborted if the branch is not fully merged.
|
# Once complete, a branch deletion is attempted, however aborted if the branch
|
||||||
|
# is not fully merged.
|
||||||
#
|
#
|
||||||
# Author: Tony Grosinger
|
# Author: Tony Grosinger
|
||||||
#
|
#
|
||||||
@ -21,7 +22,7 @@
|
|||||||
# Dependencies
|
# Dependencies
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
#
|
#
|
||||||
# * Git Top (Used to pull from master and rebase)
|
# * Git Top (Used to pull from the default branch and rebase)
|
||||||
#
|
#
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
# Installation
|
# Installation
|
||||||
@ -37,6 +38,10 @@
|
|||||||
# fi
|
# fi
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
|
# Ensure the following is in your .gitconfig alias section:
|
||||||
|
#
|
||||||
|
# default-branch = "!git symbolic-ref refs/remotes/origin/HEAD | cut -f4 -d/"
|
||||||
|
#
|
||||||
|
|
||||||
VERSION="v0.0.2"
|
VERSION="v0.0.2"
|
||||||
|
|
||||||
@ -45,6 +50,8 @@ BLUE="\e[34m"
|
|||||||
RED="\e[91m"
|
RED="\e[91m"
|
||||||
CLEAR="\e[0m"
|
CLEAR="\e[0m"
|
||||||
|
|
||||||
|
DEFAULT_BRANCH=$(git default-branch)
|
||||||
|
|
||||||
version() {
|
version() {
|
||||||
echo "git safedel ${VERSION}"
|
echo "git safedel ${VERSION}"
|
||||||
echo ""
|
echo ""
|
||||||
@ -55,7 +62,7 @@ usage() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo "If branch name is omitted, current branch will be deleted"
|
echo "If branch name is omitted, current branch will be deleted"
|
||||||
echo "Only safe deletes are attempted. If delete fails, then command"
|
echo "Only safe deletes are attempted. If delete fails, then command"
|
||||||
echo "only acts as a rebase against master."
|
echo "only acts as a rebase against the default branch."
|
||||||
}
|
}
|
||||||
|
|
||||||
print_cmd() {
|
print_cmd() {
|
||||||
@ -119,7 +126,7 @@ require_clean_work_tree() {
|
|||||||
|
|
||||||
delete_branch() {
|
delete_branch() {
|
||||||
local startbranch=${1}
|
local startbranch=${1}
|
||||||
exec_cmd "git checkout -q master"
|
exec_cmd "git checkout -q ${DEFAULT_BRANCH}"
|
||||||
exec_cmd "git branch -d ${startbranch}"
|
exec_cmd "git branch -d ${startbranch}"
|
||||||
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
@ -156,8 +163,8 @@ main() {
|
|||||||
|
|
||||||
print_status "Attempting to delete branch: ${startbranch}"
|
print_status "Attempting to delete branch: ${startbranch}"
|
||||||
|
|
||||||
if [ ${startbranch} = "master" ]; then
|
if [ ${startbranch} = "${DEFAULT_BRANCH}" ]; then
|
||||||
echo "Cannot delete branch \"master\""
|
echo "Cannot delete branch \"${DEFAULT_BRANCH}\""
|
||||||
echo "Please switch branch or provide a branch name as an argument."
|
echo "Please switch branch or provide a branch name as an argument."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -11,8 +11,8 @@
|
|||||||
# Summary
|
# Summary
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Performs a pull from origin onto master before rebasing the current branch on
|
# Performs a pull from origin onto the default branch before rebasing the
|
||||||
# master.
|
# current branch on to the default branch.
|
||||||
#
|
#
|
||||||
# Author: Tony Grosinger
|
# Author: Tony Grosinger
|
||||||
#
|
#
|
||||||
@ -30,6 +30,10 @@
|
|||||||
# fi
|
# fi
|
||||||
# }
|
# }
|
||||||
#
|
#
|
||||||
|
# Ensure the following is in your .gitconfig alias section:
|
||||||
|
#
|
||||||
|
# default-branch = "!git symbolic-ref refs/remotes/origin/HEAD | cut -f4 -d/"
|
||||||
|
#
|
||||||
|
|
||||||
VERSION="v0.0.2"
|
VERSION="v0.0.2"
|
||||||
|
|
||||||
@ -38,6 +42,8 @@ BLUE="\e[34m"
|
|||||||
RED="\e[91m"
|
RED="\e[91m"
|
||||||
CLEAR="\e[0m"
|
CLEAR="\e[0m"
|
||||||
|
|
||||||
|
DEFAULT_BRANCH=$(git default-branch)
|
||||||
|
|
||||||
version() {
|
version() {
|
||||||
echo "git top ${VERSION}"
|
echo "git top ${VERSION}"
|
||||||
echo ""
|
echo ""
|
||||||
@ -113,21 +119,21 @@ checkout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pull_remote() {
|
pull_remote() {
|
||||||
checkout "master"
|
checkout "${DEFAULT_BRANCH}"
|
||||||
exec_cmd "git pull -r -q"
|
exec_cmd "git pull -r -q"
|
||||||
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo >&2 "Could not pull on master, please check that upstream is set and try again."
|
echo >&2 "Could not pull on ${DEFAULT_BRANCH}, please check that upstream is set and try again."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
rebase() {
|
rebase() {
|
||||||
local startbranch=${1}
|
local startbranch=${1}
|
||||||
exec_cmd "git rebase -q master ${startbranch}"
|
exec_cmd "git rebase -q ${DEFAULT_BRANCH} ${startbranch}"
|
||||||
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
echo >&2 "Could not rebase ${startbranch} on master, rolling back changes."
|
echo >&2 "Could not rebase ${startbranch} on ${DEFAULT_BRANCH}, rolling back changes."
|
||||||
echo >&2 "Please manually resolve conflicts."
|
echo >&2 "Please manually resolve conflicts."
|
||||||
|
|
||||||
git rebase --abort
|
git rebase --abort
|
||||||
@ -168,8 +174,10 @@ main() {
|
|||||||
|
|
||||||
require_clean_work_tree
|
require_clean_work_tree
|
||||||
|
|
||||||
if [ ${startbranch} = "master" ]; then
|
git fetch -p
|
||||||
print_status "Already on master, only performing git pull"
|
|
||||||
|
if [ ${startbranch} = "${DEFAULT_BRANCH}" ]; then
|
||||||
|
print_status "Already on ${DEFAULT_BRANCH}, only performing git pull"
|
||||||
pull_remote
|
pull_remote
|
||||||
else
|
else
|
||||||
pull_remote
|
pull_remote
|
||||||
|
Loading…
Reference in New Issue
Block a user