Tuesday, November 26, 2013

Git basics

Typical process:

Make changes
git add .
git commit -a -m "What I am changing"
git push

Add the files in your new Rails project to Git and then commit the results:
$ git add .
$ git commit -m "Initialize repository"

Identify changed files:
$ git status

View commit messages:
$ git log


Start a new branch:
$ git checkout -b my-new-branch

List branches:
$ git branch

Commit all the new changes since last commit:
$ git commit -a -m "Describe what these changes do"

Merge my new branch back into master:
$ git checkout master 

$ git merge my-new-branch

Delete the branch that is no longer needed
$ git branch -d my-new-branch



Undo screwups:
This rolls back to the last commit in the current branch.

The -f flag forces Git to overwrite changes since the last commit.
$ git checkout -f 


Undo a major screwup: 
This rolls back to a different branch and deletes the messed up branch
$ git checkout -b my-new-branch 
$ [do some stuff to really mess up the branch] 
$ git add . 
$ git commit -a -m "Major screw up" 
$ git checkout master 
$ git branch -D my-new-branch


[Notes taken from Ruby on Rails Tutorial]