Slydders GIT cheatsheet

Here it is. The cheatsheet I always find handy when dealing with GIT.

setup the remote repository

chuck@Vacant [master] ~/Projects/splinked$ ssh chuck@Vacant [master] ~/Projects/splinked$ mkdir my_project.git chuck@Vacant [master] ~/Projects/splinked$ cd my_project.git chuck@Vacant [master] ~/Projects/splinked$ git init –bare chuck@Vacant [master] ~/Projects/splinked$ git-update-server-info chuck@Vacant [master] ~/Projects/splinked$ exit

On local machine

chuck@Vacant [master] ~/Projects/splinked$ cd my_project chuck@Vacant [master] ~/Projects/splinked$ git init chuck@Vacant [master] ~/Projects/splinked$ git add * chuck@Vacant [master] ~/Projects/splinked$ git commit -m “My initial commit message” chuck@Vacant [master] ~/Projects/splinked$ git remote add origin chuck@Vacant [master] ~/Projects/splinked$ git push -u origin master

Checkout from Subversion

 1. cd /path/to/git/localrepo
 2. svn mkdir --parents protocol:///path/to/repo/PROJECT/trunk -m "Importing git repo"
 3. git svn init protocol:///path/to/repo/PROJECT -s
 4. git svn fetch
 5. git rebase trunk
 5.1.  git status
 5.2.  git add (conflicted-files)
 5.3.  git rebase --continue
 5.4.  (repeat 5.1.)
 6. git svn dcommit

Hard Reset

When applying/popping a stash and everything just decides to dump on you then you may have no other option:

git reset --hard

.bashrc entries

Have your terminal prompt display what branch you are currently on in red.

function parse_git_branch_and_add_brackets {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\ \[\1\]/'
PS1="\[\e]0;\w\a\]\n\[\e[32m\]\u@\h\[\033[0;31m\]\$(parse_git_branch_and_add_brackets) \[\e[33m\]\w\[\e[0m\]\$ "

Generates a prompt such as:

chuck@Vacant [master] ~/Projects/splinked$ cd .. chuck@Vacant ~/Projects/splinked$

git aliases

# aliases for common git commands
alias g='git'
alias st='git status'
alias push='git push'
alias commit='git commit'
alias log='git log'
alias stash='git stash'
alias checkout='git checkout'
alias branch='git branch'
alias fetch='git fetch'
alias merge='git merge'
alias cherry-pick='git cherry-pick'
alias rebase='git rebase'

# 'git pull --rebase' with a short log of the latest changes
pull () { local HEADHASH=`git describe --always --abbrev=40`; git pull --rebase $*; echo; PAGER='cat -B' git log --format="%C(yellow)%h %C(green)%an%C(reset): %s" $HEADHASH.. | sed -nr 's/([^:]+)\:/\1\t/;p'; }

# 'git pull --ff-only' with a short log of the latest changes
ff () { local HEADHASH=`git describe --always --abbrev=40`; git pull --ff-only $*; echo; PAGER='cat -B' git log --format="%C(yellow)%h %C(green)%an%C(reset): %s" $HEADHASH.. | sed -nr 's/([^:]+)\:/\1\t/;p'; }

# verbose add
add () { git add -v $*; git status; }

# verbose reset
reset () { git reset $*; git status; }

# 'git add' with 'git ls-files' and grep
# usage like grep - example: gadd 'readme.txt'
gadd () { git ls-files -co --exclude-standard | grep $* | xargs git add -v; git status; }

# 'git reset' with 'git ls-files' and grep
greset () { git ls-files | grep $* | xargs git reset; git status; }

# Enable auto-completion for aliased 'git' command
complete -o default -o nospace -F _git g

get_git_branch() {
  echo `git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
alias gpull='git pull origin `get_git_branch`'
alias gpush='git push origin `get_git_branch`'

Removing files/directories directly from the SVN server

chuck@Vacant [master] ~/Projects/splinked$ cd .. chuck@Vacant ~/Projects/splinked$

/var/customers/webs/cw01/wiki/data/pages/development/git_cheats.txt · Last modified: 2012/04/27 10:10 by wadmin
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki