Git

From Knowledge Base
Jump to: navigation, search

My page about git

Initial outline / topic/content brainstorming:

  • my gitconfig file
  • Most useful git commands
  • Misc/All git tasks & commands
  • BASIC useful workflows - (closer related to Tasks)
  • git bookmarks


git config

Your (user-global) git config file should be stored as `~/.gitconfig` (stored in home directory, as filename `.gitconfig`).

Here is my helpful one you can download:

(Until I figure out Attachments / File Upload, here's the copy & paste instead)

### RL - last updated [3/17/16]
 
[user]
        name = DummyName ReplaceMe
        email = dummy@replaceme.com
 
# color {{{
[color]
    branch = auto
    diff = auto
    status = auto
 
[color "branch"]
    current = red reverse
    local = blue
    remote = green
 
[color "diff"]
    meta = yellow bold
    frag = magenta bold
    old = red bold
    new = green bold
 
[color "status"]
    added = green
    changed = yellow
    untracked = red
 
# }}}
 
# push {{{
[push]
    ;(not till git 2.0!) only push to remotes with same name as current (local) branch
    default = simple
    ;push current branch to remote branch of same name
    ;default = current
    ;push current branch to branch whose changes are normally pulled into current
    ;default = upstream
 
# }}}
 
# alias {{{
[alias]
    unstage = reset HEAD --
    st = status
    cl = clone
    ci = commit
    co = checkout
    br = branch 
 
    ## Log graph view commands
    # main decorated log graph view
    ldg = log --graph --decorate --oneline --all
    # short list of log graph and force return
    lsg = "!GIT_PAGER=cat git ldg --color=always -17"
    # (test attempts at short graph log, based on terminal size - not working)
    ltg = "!bash -c 'f() { echo \"this many: $LINES\"; git ldg -$(($LINES-6));}; f'"
    tldg = log --graph --decorate --oneline --all -"${LINES}"
    tlsg = '!git ldg -$(($LINES-6))'
 
    lbg = log --graph --decorate --oneline --branches
    llg = log --graph --decorate --oneline --branches --not master
 
    le = log --oneline --decorate
    ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%an]" --decorate --numstat
    ls1 = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%an]" --decorate
    lds = log --pretty=format:"%C(yellow)%h\\ %C(green)%ad%Cred%d\\ %Creset%s%Cblue\\ [%an]" --decorate --date=short --graph
    ls = log --pretty=format:"%C(green)%h\\ %C(yellow)[%ad]%Cred%d\\ %Creset%s%Cblue\\ [%an]" --decorate --date=relative
    lc  = "!f() { git ll "$1"^.."$1"; }; f"
    lnc = log --pretty=format:"%h\\ %s\\ [%an]"
 
    #list all aliases
    la = "!git config -l | grep alias | cut -c 7-"
    diff = diff --word-diff
    d = diff --word-diff
    dc = diff --cached
    #list modified files in last commit
    dl = "!git ll -1"
    #diff last commit
    dlc = diff --cached HEAD^
 
    #reset commands
    r = reset
    r1 = reset HEAD^
    r2 = reset HEAD^^
    rh = reset --hard
    rh1 = reset HEAD^ --hard
    rh2 = reset HEAD^^ --hard
 
    #grep on filename
    f = "!git ls-files | grep -i"
 
    lasttag = describe --tags --abbrev=0
    lt = describe --tags --abbrev=0
 
    #list remotes
    rem="!git config -l | grep remote.*url | tail -n +2"
 
    # (would ideally like to be able to pass specific stash after '-p ___')
    stash-unapply = !git stash show -p | git apply -R
 
# }}}
 
[sendemail]
	;; http://www.freedesktop.org/wiki/Software/PulseAudio/HowToUseGitSendEmail/
	;; replace the smtp server w/ your own mail server (this worked for gmail for me)
	smtpserver = smtp.replacememailserver.cxm
	;smtpencryption = tls
	;smtpuser = dummy@replaceme.com
[credential]
	helper = cache --timeout=3600
[rerere]
	enabled = true
 
 
 
##### WIP - Don't trust anything below here, still figuring it out #####
 
# difftool {{{
[difftool]
    prompt = false
    tool = meld
 
[diff]
    #external = git-meld
 
## hacking bc difftool - not sure if it is working {{{
#;bc4 uses alias hack to link for bc3:
#; alias bc3=/usr/bin/bcompare
#[diff]
#    #external = git-meld
#    tool = bc3
#    guitool = bc3
#
#[difftool]
#    prompt = false
#    tool = bc3
#    ;tool = meld
#
#[difftool "bc3"]
#    trustExitCode = true
#
#[merge]
#    tool = bc3
#
#[mergetool]
#    prompt = false
#    tool = bc3
#[mergetool "bc3"]
#    trustExitCode = true
#
# }}}
 
# }}}
 
 
##### END of WIP Section #####


Setup:

  • Save it in your home directory with the filename `.gitconfig` (`~/.gitconfig`)
  • Need to modify it for your own account, by replacing the dummy Name & Email with your own.

Includes helpful aliases, and configs:

  • Enables shortcuts and aliases for most common git commands (e.g. `$ git st` for `$ git status`)
  • Most helpful: Git log 'graph' aliases (e.g. `$ git ldg`). Show a decorated graph view of the git log, with branches, forks, tags and remotes.

You need to modify it for your own setup by replacing the UserName and Email to match your own (used in commits, and maybe should match your sshkey).


NOTE: This works well in combination w/ ssh keys setup and a .bashrc custom prompt (PS1) that shows VCS info.

Could Also Include:

  • useful git configs, for file, repo, etc