Bash/Git: Refactor Git aliases, remove aliases exists in git-extras.
This commit is contained in:
		@@ -31,10 +31,10 @@
 | 
			
		||||
 | 
			
		||||
* *oo* → open .
 | 
			
		||||
 | 
			
		||||
* *marked* → open -a marked
 | 
			
		||||
 | 
			
		||||
* *e* → subl
 | 
			
		||||
 | 
			
		||||
* *gh* → github
 | 
			
		||||
 | 
			
		||||
* *+x* → chmod +x
 | 
			
		||||
 | 
			
		||||
* *md <dir>* → Make directory and `cd` to it.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										20
									
								
								docs/Git.md
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								docs/Git.md
									
									
									
									
									
								
							@@ -32,27 +32,15 @@ Simple one-line-per-commit log.
 | 
			
		||||
 | 
			
		||||
Log with list of changed files for each commit.
 | 
			
		||||
 | 
			
		||||
###	git ignore <file mask>
 | 
			
		||||
 | 
			
		||||
Add new item to `.gitignore`.
 | 
			
		||||
 | 
			
		||||
### git this
 | 
			
		||||
 | 
			
		||||
Initialize Git repo in current folder and commit all files.
 | 
			
		||||
 | 
			
		||||
### git append
 | 
			
		||||
### git-append
 | 
			
		||||
 | 
			
		||||
Add all staged files to previous commit.
 | 
			
		||||
 | 
			
		||||
### git undo
 | 
			
		||||
 | 
			
		||||
Undo last commit withould loosing any changes.
 | 
			
		||||
 | 
			
		||||
### git conflicts
 | 
			
		||||
### git-conflicts
 | 
			
		||||
 | 
			
		||||
List of files with unresolved conflicts.
 | 
			
		||||
 | 
			
		||||
### gr
 | 
			
		||||
### git-root (or gr)
 | 
			
		||||
 | 
			
		||||
Jump to root folder of Git repo.
 | 
			
		||||
 | 
			
		||||
@@ -70,7 +58,7 @@ Add remote upstream.
 | 
			
		||||
 | 
			
		||||
### git-upstream [branch]
 | 
			
		||||
 | 
			
		||||
Sync branch with upstream.
 | 
			
		||||
Sync branch (`master` by default) with upstream.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## [git-friendly](https://github.com/jamiew/git-friendly)
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ alias pjm="cd ~/Dropbox/Projects/!"
 | 
			
		||||
alias o="open"
 | 
			
		||||
alias oo="open ."
 | 
			
		||||
alias e="subl"
 | 
			
		||||
alias marked="open -a marked"
 | 
			
		||||
alias gh="github"
 | 
			
		||||
alias +x="chmod +x"
 | 
			
		||||
 | 
			
		||||
# Detect which `ls` flavor is in use
 | 
			
		||||
@@ -82,9 +82,6 @@ password() { openssl rand -base64 ${1:-8} | c; }
 | 
			
		||||
# Show $PATH in a readable way
 | 
			
		||||
alias path='echo -e ${PATH//:/\\n}'
 | 
			
		||||
 | 
			
		||||
# Git root
 | 
			
		||||
alias gr='git rev-parse 2>/dev/null && cd "./$(git rev-parse --show-cdup)"'
 | 
			
		||||
 | 
			
		||||
# NPM
 | 
			
		||||
alias npm-patch='npm version patch -m "%s"'
 | 
			
		||||
alias npm-release='npm version minor -m "%s"'
 | 
			
		||||
 
 | 
			
		||||
@@ -141,45 +141,6 @@ function yay() {
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Setup syncronization of current Git repo with GitHub repo of the same name
 | 
			
		||||
# USAGE: git-github [repo]
 | 
			
		||||
function git-github() {
 | 
			
		||||
	user="sapegin"
 | 
			
		||||
	repo=${1-`basename "$(pwd)"`}
 | 
			
		||||
	git remote add origin "git@github.com:$user/$repo.git"
 | 
			
		||||
	git push -u origin master
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Setup syncronization of current Git repo with Bitbucket repo of the same name
 | 
			
		||||
# USAGE: git-bitbucket [repo]
 | 
			
		||||
function git-bitbucket() {
 | 
			
		||||
	user="sapegin"
 | 
			
		||||
	repo=${1-`basename "$(pwd)"`}
 | 
			
		||||
	git remote add origin "git@bitbucket.org:$user/$repo.git"
 | 
			
		||||
	git push -u origin master
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Add remote upstream
 | 
			
		||||
# USAGE: git-fork <original-author>
 | 
			
		||||
function git-fork() {
 | 
			
		||||
	user=$1
 | 
			
		||||
	if [[ "$user" == "" ]]; then
 | 
			
		||||
		echo "Usage: git-fork <original-author>"
 | 
			
		||||
	else
 | 
			
		||||
		repo=`basename "$(pwd)"`
 | 
			
		||||
		git remote add upstream "git@github.com:$user/$repo.git"
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Sync branch with upstream
 | 
			
		||||
# USAGE: git-upstream [branch]
 | 
			
		||||
function git-upstream() {
 | 
			
		||||
	branch=${1-master}
 | 
			
		||||
	git fetch upstream
 | 
			
		||||
	git checkout $branch
 | 
			
		||||
	git merge upstream/$branch
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Find files with Windows line endings (and convert then to Unix in force mode)
 | 
			
		||||
# USAGE: crlf [--force]
 | 
			
		||||
function crlf() {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										56
									
								
								includes/bash_git.bash
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								includes/bash_git.bash
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,56 @@
 | 
			
		||||
# Git related Bash aliases
 | 
			
		||||
 | 
			
		||||
github_user="sapegin"
 | 
			
		||||
bitbucket_user="sapegin"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# `cd` to repo root
 | 
			
		||||
alias git-root='git rev-parse 2>/dev/null && cd "./$(git rev-parse --show-cdup)"'
 | 
			
		||||
alias gr="git-root"
 | 
			
		||||
 | 
			
		||||
# Setup syncronization of current Git repo with GitHub repo of the same name
 | 
			
		||||
# USAGE: git-github [repo]
 | 
			
		||||
function git-github() {
 | 
			
		||||
	local repo=${1-`basename "$(pwd)"`}
 | 
			
		||||
	git remote add origin "git@github.com:$github_user/$repo.git"
 | 
			
		||||
	git push -u origin master
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Setup syncronization of current Git repo with Bitbucket repo of the same name
 | 
			
		||||
# USAGE: git-bitbucket [repo]
 | 
			
		||||
function git-bitbucket() {
 | 
			
		||||
	local repo=${1-`basename "$(pwd)"`}
 | 
			
		||||
	git remote add origin "git@bitbucket.org:$bitbucket_user/$repo.git"
 | 
			
		||||
	git push -u origin master
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Add remote upstream
 | 
			
		||||
# USAGE: git-fork <original-author>
 | 
			
		||||
function git-fork() {
 | 
			
		||||
	local user=$1
 | 
			
		||||
	if [[ "$user" == "" ]]; then
 | 
			
		||||
		echo "Usage: git-fork <original-author>"
 | 
			
		||||
	else
 | 
			
		||||
		local repo=`basename "$(pwd)"`
 | 
			
		||||
		git remote add upstream "git@github.com:$user/$repo.git"
 | 
			
		||||
	fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Sync branch with upstream
 | 
			
		||||
# USAGE: git-upstream [branch]
 | 
			
		||||
function git-upstream() {
 | 
			
		||||
	local branch=${1-master}
 | 
			
		||||
	git fetch upstream
 | 
			
		||||
	git checkout $branch
 | 
			
		||||
	git merge upstream/$branch
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# Add all staged files to previous commit
 | 
			
		||||
function git-append() {
 | 
			
		||||
	git log -n 1 --pretty=tformat:%s%n%n%b | git commit -F - --amend
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# List of files with unresolved conflicts
 | 
			
		||||
function git-conflicts() {
 | 
			
		||||
	git ls-files -u | awk '{print $4}' | sort -u
 | 
			
		||||
}
 | 
			
		||||
@@ -61,8 +61,8 @@ INVERT="$(tput sgr 1 0)"
 | 
			
		||||
NOCOLOR="$(tput sgr0)"
 | 
			
		||||
 | 
			
		||||
# Load prompt and aliases
 | 
			
		||||
for file in ~/dotfiles/includes/{bash_prompt,bash_aliases,bash_functions}; do
 | 
			
		||||
	[ -r "$file.bash" ] && source "$file.bash"
 | 
			
		||||
for file in ~/dotfiles/includes/bash_{prompt,aliases,functions,git}.bash; do
 | 
			
		||||
	[ -r "$file" ] && source "$file"
 | 
			
		||||
done
 | 
			
		||||
unset file
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -27,11 +27,6 @@
 | 
			
		||||
	s = status -sb
 | 
			
		||||
	l = log --graph --pretty=format:'%C(magenta)%h%C(blue)%d%Creset %s %C(blue bold)- %an, %ar%Creset'
 | 
			
		||||
	ll = log --stat --abbrev-commit
 | 
			
		||||
	ignore = !([ ! -e .gitignore ] && touch .gitignore) | echo $2 >> .gitignore
 | 
			
		||||
	this = !git init && git add . && git commit -m \"Initial commit.\"
 | 
			
		||||
	append = !git log -n 1 --pretty=tformat:%s%n%n%b | git commit -F - --amend
 | 
			
		||||
	undo = reset --mixed HEAD^
 | 
			
		||||
	conflicts = !git ls-files -u | awk '{print $4}' | sort -u
 | 
			
		||||
[push]
 | 
			
		||||
	default = current
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user