Monday, September 2, 2013

git cheat sheet

Here's my personal cheat sheet for using git.  Use at your own risk.

Change the name of a local branch.

  • git checkout "name_of_old_branch"
  • git branch -m "new_branch_name"

Merge Branches

  • git checkout -b "new_branch_to_work_on"
  • make changes ...
  • git commit -a
  • git checkout "master"
  • git merge "new_branch_to_work_on"
  • change from "new_branch_to_work_on" should be merged into master

What is the status (what files have changed)

  • git status

Setting up which program to use for diff'ing files:

  • git config --global diff.tool vimdiff
    • This makes vimdiff your difftool.
  • git config --global difftool.prompt false
    • This stops git from asking you if this difftool should be used

What changes have I made to a file (since last commit)?

  • git diff filename
  • git difftool filename

How has my file changed?

  • git log <filename>
    • This gets revision #'s and log notes.
  • git diff <revision#> <filename>
    • This compares latest revision with the specified version.
  • git diff <oldrevision#> <newrevision#> <filename

How to make a new repository?

  • git init
  • git add .
    • This will add all files to a repository.
  • git commit -a 
    • Commit file additions to repository.

No comments:

Post a Comment