Skip to content

Instantly share code, notes, and snippets.

@antillas21
Created March 13, 2012 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antillas21/2027596 to your computer and use it in GitHub Desktop.
Save antillas21/2027596 to your computer and use it in GitHub Desktop.
Como mostrar el branch en que trabajamos si usamos Git
## Agregar en nuestro archivo ~/.gitconfig
[alias]
hist = log --graph --pretty=format:'%C(yellow)%h%Creset -%C(green)%d%Creset %s %C(cyan)(%cr) %C(magenta)<%an>%Creset' --abbrev-commit --date=relative
# hist es un alias, en el ejemplo que se menciona, al escribir en el shell:
$ git hist
# obtendríamos la siguiente salida:
* 56afae3 - (HEAD, origin/master, master) Added job field to Attendee model. (5 weeks ago) <Antonio Antillon>
* 179672f - Fixed collision from merge. (5 weeks ago) <Antonio Antillon>
|\
| * e54b5ad - (origin/reporting, reporting) Created report export method and added records per printed status window on Statistics. (5 weeks ago) <Antonio Antillon>
| * ca69a07 - Adding statistics for AttendeeTypes. (5 weeks ago) <Antonio Antillon>
| * 26b0d44 - Removed unused statistics.html.haml file. (5 weeks ago) <Antonio Antillon>
| * 4d9a920 - Moving statistics to ReportsController. (5 weeks ago) <Antonio Antillon>
| * 156313c - Building basic statistics for Attendee records. (5 weeks ago) <Antonio Antillon>
| * 41ccbc3 - Changing munger gem version. (5 weeks ago) <Antonio Antillon>
...
...
...
# donde el hash que identifica el commit estará en color amarillo.
# el mensaje del commit en el color default del texto del shell.
# la fecha relativa en color cyan.
# el nombre del autor del commit en color magenta.
# Agregamos esto a nuestro .bashrc o .bash_profile ----
# Display git branch
function parse_git_branch {
[ -d .git ] || return 1
git_status="$(git status 2> /dev/null)"
branch_pattern="^# On branch ([^${IFS}]*)"
remote_pattern="# Your branch is (.*) of"
diverge_pattern="# Your branch and (.*) have diverged"
if [[ ! ${git_status}} =~ "working directory clean" ]]; then
state="*"
fi
# add an else if or two here if you want to get more specific
if [[ ${git_status} =~ ${remote_pattern} ]]; then
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then
remote="↑"
else
remote="↓"
fi
fi
if [[ ${git_status} =~ ${diverge_pattern} ]]; then
remote="↕"
fi
if [[ ${git_status} =~ ${branch_pattern} ]]; then
branch=${BASH_REMATCH[1]}
echo " [${branch}${state}${remote}]"
fi
}
export PS1='\[\033[0;36m\]\w\[\033[0m\]$(parse_git_branch)$ '
## --- fin ---
# Esto nos da como resultado, un shell prompt así:
~/Documents/Apps/2011/registrame [master]$
# cuando el branch está limpio.
~/Documents/Apps/2011/registrame [master*]$
# cuando hemos hecho cambios y no hemos hecho commit.
~/Documents/Apps/2011/registrame [master↑]$
# cuando nuestro repositorio local está 1 o N commits adelante del repositorio remoto.
~/Documents/Apps/2011/registrame [master↓]$
# cuando el repositorio remoto está 1 o N commits adelante de nuestro repositorio local.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment