Lesson 2

Udacity – How to Use Git and GitHub

Lesson 2

Repositories

  • git init to create a new git repository. There is no commit when create.
  • git log to see what commit has been done at anytime
  • git status show which file has changed since the last commit
  • git add to add file to staging are for next commit
  • git commit will commit the file in staging (-m option to add with a message / comment)
  • git diff without argument compare working directory with staging area
  • git diff –staged compare staging area file with most recent commit in repository
  • git reset –hard to discard any changes in working directory and staging area (cannot reverse this)
  • git checkout master will leave ‘detached head’ state and put you back in the lastest commit.

Branches

  • git branch (no argument) show all branches (* is the one currently checkout)
  • git branch (with an argument) create a new branch
  • git checkout [branch name] to check out a branch
  • git log –graph –oneline [branch..] will show a graph of how each branch connect to each other.
  • git checkout -b [new branch name] is equivalent to run both git branch [new branch name] and then git checkout [new branch name]

Merge

  • if both file have the same line, keep that line
  • if original file have it and one of the file deleted it, then delete it
  • if original file don’t have it and one of the file added it, then add it
  • git merge branchid1 branchid2 to merge branchid2 into branchid1
  • git show commit to show the changes between a commit and its parent
  • git branch -d branchid to delete a branch label
  • git log -n 1 will only show one commit
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s