Git & Github: Basics of Distributed Version Control
Git & Github: Basics of Distributed Version Control
Git & Github: Basics of Distributed Version Control
Charles Liu
Overview
¤ We’ll talk about two commands that are not safe today
¨ 3 possible states for a file
¤ Changed
¤ Staged
¤ Committed
Basic workflow
¨ git init – create git project in existing directory
¤ Make Git start to “watch” for changes in the directory
¨ The basic workflow:
Basic workflow
working tree
The git status output
The git log output
The staging area
¨ git add takes the snapshot of the file that will be
committed à you can change the file after adding it
The staging area
¨ To remove a file from the working tree and in the next
commit, simply git rm <filename>
¨ To remove it from the next commit, but keep the file in
https://github.com/github/gitignore
Use case #2: branching
q What is a branch?
q Branching commands
q The HEAD pointer
q Basics of merging
q Basics of rebasing
q Aside: the git reset command
What is a branch?
created.
¨ In Git, branches are actually just a pointer to these
commits
Branching commands
<branchname>
¨ Delete a branch – git branch –d <branchname>
Stashing
HEAD
HEAD
HEAD
Conflict markers
Merge conflicts
Rebasing
HEAD
Rebasing
HEAD
Rebasing
https://help.github.com/articles/generating-ssh-
keys
Github – SSH keys
¨ cd ~/.ssh; ls
¨ If a file named id_dsa.pub or id_rsa.pub does not
exist:
¤ ssh-keygen -t dsa -C “<your email here>”
¤ ssh-add id_dsa
3. Click “Add
SSH key”
2. Click “SSH
Keys”
¨ When you do git fetch, you don’t immediately see the
changes. Why?
¨ Changes are fetched to a “remote tracking branch”
q Branches
q The HEAD pointer, merging, and rebasing
q Remotes
q Pushing and fetching; quick introduction to Github
Lots of other topics
¨ Tags and version numbers
¨ Interactive rebase: squashing and amending commits
¨ Submodules
¨ …more!
For more information
¨ The book Pro Git (which I based much of this
presentation on), available for free!
¤ https://github.s3.amazonaws.com/media/progit.en.pdf
¤ Covered
Chapters 1-3 in detail, very simple ideas from
Chapters 4-6
¨ Git documentation: do git help <commandname>
¨ Google, StackOverflow, etc.
That’s all for today!
¨ We’re done with client-side technologies!
¨ Office hours tonight, 7-9pm in 32-044 (basement of
Stata)