selfjungle Just another WordPress weblog

7May/180

colorful bash prompt with git branch

Edit .bashrc :

export COLOR_NC='\e[0m' # No Color
export COLOR_WHITE='\e[1;37m'
export COLOR_BLACK='\e[0;30m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
export COLOR_RED='\e[0;31m'
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_PURPLE='\e[0;35m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_BROWN='\e[0;33m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_GRAY='\e[0;30m'
export COLOR_LIGHT_GRAY='\e[0;37m'

function parse_git_dirty {
    [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit, working directory clean" ]] && echo "*"
}
function parse_git_branch {
    git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
}
PS1=""
PS1=$PS1"\[$COLOR_GREEN\]\u@\h\:"                # Display user@host
#PS1=$PS1"\[$Yellow\]\@:"                        # Display time
#PS1=$PS1"\[$Blue\][\[$Cyan\]\d\[$Blue\]] "      # Display date
#PS1=$PS1"\[$Yellow\]\@:"                        # Display time
PS1=$PS1"\[$COLOR_CYAN\]\w"                      # Display pwd
PS1=$PS1"\[$COLOR_BROWN\]"'$(parse_git_branch)'  # Display git-branch
PS1=$PS1"\[$COLOR_NC\]$ "                        # Turn off color and end prompt
export PS1=$PS1  
Tagged as: , No Comments
8Mar/180

git checkout pull requests

Edit .git/config :

[remote "origin"]
        url = ...
#       fetch = +refs/heads/*:refs/remotes/origin/*
        fetch = +refs/pull/*/head:refs/remotes/origin/pull/*
Tagged as: No Comments
31Oct/160

git word diff

git diff --word-diff=color

shows changes in place.

Tagged as: No Comments
10Apr/140

Export/apply git diff as patch

git diff > save.patch
patch -p1 < save.patch

Link: Stackoverflow

Tagged as: No Comments
25Oct/130

git auto-completion

wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -O ~/.git-completion.bash
source ~/.git-completion.bash
Tagged as: , No Comments
18Oct/130

pushing to a non-bare git repo

Init a directory as a bare repo in the first place:

git init . # non-bare
git init -bare . # bare

To be able to push into a non-bare repo, just check out a branch users don't push to:

git checkout -b DUMMY_BRANCH_DONT_USE

Or turn it into a bare repo:

rm *
mv .git/* .
rm .git
sed -i 's/bare = false/bare = true/' config

Source: gitolite

Tagged as: No Comments
26Sep/130

git ignoring changes

Ignoring files in repository:

edit .gitignore
git update-index --[no-]assume-unchanged FILE # if rule was added after the tracked file

Ignoring files in all repositories on your computer:

edit ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global

Ignoring local per-repository files:

edit .git/info/exclude

Source: github help

Tagged as: No Comments
18Jul/110

git tag

Tag commit:

git tag <tagname> -m <msg> #lightweight
git tag -a <tagname> -m <msg> #annotated, preferred

Push tags (not done by default):

git push --tags <remote> <branch> #dangerous, avoid pushing all tags!
git push  <remote>  <tagname>

Fetch tags

git fetch --tags <remote> <branch> #or
git remote update <remote> 

Look up which branch has the tag

git branch --all --contains <tagname>

delete tags remote and local:

git push --delete origin <tagname>
git tag -d  <tagname>
Tagged as: No Comments