Skip to content
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
130 lines (95 sloc) 5.56 KB
layout title
Useful Git Commands

Table of Contents

Git tricks

Git command line

  • git log --oneline --graph -- great logging output
  • export GIT_CURL_VERBOSE=1;git clone ... -- show the verbose output of the git curl

Git usage


  • git init -- initialize a git repo in the current directory (you still need to add and commit the local files)
  • git config -l -- view git configs
  • git config --global http.proxy -- set http proxy in git config
  • git branch -r --contains origin/my_release -- find all remote branches that contain the commits in my_release branch
  • git diff-tree -r --root <SHA> -- see a full diff-tree
  • git svn clone {svn_url} -- clone an SVN repo as a git repository. more info

Remote Repo Commands

  • git clone -o notorigin -- sets the remote to "notorigin"
  • git clone -b branch_name -- clone and checkout a specific remote branch
  • git remote add origin -- set a new remote
  • git remote set-url origin -- change the remote URL for origin
  • git remote update -- update the local repo with remote tracking branches
  • git remote prune origin -- remove stale tracking branches
  • git remote update -- update branches from remote repos. Use this if you don't see you branch using git branch -r
  • git remote -v -- verify new remote
        # origin (fetch)
        # origin (push)

Local Repo Commands

  • git branch -r -- view available remote branches
  • git branch -vv -- view the tracking branch
  • git checkout --track origin/serverfix -- change the tracking branch
  • git diff --cached -- shows changes in index
  • git rm --cached -- remove file from the index but not working dir
  • git clean -f -X -d -- remove all unstaged files (great for cleaning up after a build)
  • git reset --hard HEAD -- reset your local branch to the HEAD commit (see Git Reset info)
  • git checkout HEAD -- folder1/pom.xml -- reset a single file to the HEAD commit
  • git show-ref -- shows the refs for the repo (still figuring this out)
  • git filter-branch --prune-empty --subdirectory-filter lib master -- split out a sub dir into a repository
  • git reset --soft HEAD~1 -- rollback a commit

Git articles

Git Workflow

Read about the Github Flow

  • git checkout -b dnorton-dev-2 origin/release-1.0.0 -- check out from a remote branch

  • git push -u origin dnorton-dev-2 -- push feature branch to remote repo

  • git pull origin dnorton-dev-2 -- pull feature branch

  • git push origin :dnorton-dev-2 -- delete the remote feature branch (see the git-scm page)

  • Github help: syncing a fork

Git Alias

    hist = log --color --pretty=format:\"%C(yellow)%h%C(reset) %s%C(bold red)%d%C(reset) 
    %C(green)%ad%C(reset) %C(blue)[%an]%C(reset)\" --relative-date --decorate

Git troubleshooting

  • to debug problems with an HTTP proxy set the environmental variable GIT_CURL_VERBOSE=1

The ours merge technique to replace master

    git checkout seotweaks  
    git merge -s ours master  
    git checkout master  
    git merge seotweaks  

See reference #7 for more info.

Github Cheatsheet


  5. (great training slides)
  6. (git concepts explained)
  8. 👍
You can’t perform that action at this time.