3. About Me
Jason Edgecombe (@edgester)
● Linux Administrator in the College of
Engineering at UNC Charlotte
● OpenAFS contributor & buildbot admin
● http://engrmosaic.uncc.edu
● https://github.com/edgester
● http://rampaginggeek.com
4. What is git?
● Distributed version control system
○ Version control system
■ Keeps snapshots of a set of folders and files
■ Let’s you go back in time to any snapshot
○ Distributed
■ All repositories are peers
■ Each repository has full history since last sync
■ Let’s you work without a network connection
■ Authority is determined by choice/convention
5. You should use git because...
● “cp” doesn’t scale (“cp file file.bak5.works”)
● allows for better metadata on snapshots
o description, timestamp, author, committer
● doesn’t clutter folders with copies
● space-efficient, only stores differences
● you don’t need a server to use it locally
6. Common Concepts
● commit - a snapshot in time
o referenced by SHA1 hash of contents
o links to all of its previous commits
o immutable/non-writable!
● branch - a writable variable that refers to a
commit
● tag - a read-only variable that refers to a
commit, with an optional message
7. Common Concepts, Part 2
● repository (a.k.a. “repo”) - A set of folders
that contains the git commit history,
optionally a working folder. Includes
branches & tags
● “remote” - “git remote” - a remote git repo
that is a peer of the current repo
● tracking branch - a local branch that is linked
to a remote branch
8. Concept Hierarchy
● repos contain remotes, branches, tags
● remotes link to tags, branches
● branches and tags refer to commits
● commits refer to files, folders,
parent commits
● repository→remote→branch/tag→commit
→files/folders
9. Common local commands
● Initialization
git config --global user.name "John Doe"
git config --global user.email jdoe@example.com
git init
● Working with files
o Modify files - git add ; git rm ; git mv
● Snapshots
o Save - git commit
o Query - git log; git blame
o Discard changes - git reset; git checkout
10. Common Remote Commands
● Copy a remote repo
o git clone <url/address>
o git checkout origin/master
● Download changes
o git pull --rebase (fetch and rebase)
o git pull
o git fetch
● Upload changes
o git push
11. A Sample Project Workflow
1. “git init” / “git clone” # only once
2. “git checkout -b origin/master
3. “git pull --rebase” # before each session
4. #while working (loop frequently)
a. # edit files
b. “get add .” # to add new files!
c. “git commit .” # commit all modified files
5. “git push” # when work unit is done
6. # goto 2
12. Best Practices
● Jason’s guideline: use “git pull --rebase”
(fetch & rebase) workflow until proficient
● Don’t store code and configuration in the
same repo. (Use .gitignore files if needed)
● DO NOT STORE SECRETS in git!
○ Passwords, ssh keys, etc.
○ May be relaxed for encrypted secrets/isolated repo.
13. Cage Match: Git vs. Subversion
Git: Svn:
Full
history
in all
repos
Only
latest
checko
ut
Branchi
ng is
Branchi
ng is
14. Sources of Confusion
● No pre-defined source of truth for multi-repo
● Many workflows available, all are valid
● Deleted things (git rm) are still in the archive
● History not easily re-written
o “Removed” objects/commits can still persist
o History rewrites can be rejected in receiving repo
● Index (.git/) vs. working folder (./)
15. Git Clients
● Command-line - included in Linux distros
● GUI
o gitk - visualizer, included in distros
o IDE’s: Eclipse, Emacs, Vim
o TortoiseGit (Windows) - terminology mismatch!
‘reset’ and ‘revert’ don’t directly map to
command-line git behavior.
17. Git Hosting
● Github - https://github.com/
o Free and unlimited repos for open source projects
o Can pay for closed repos
o De facto standard for OSS project collaboration
● BitBucket - https://bitbucket.org/
o Free for a project with up to 5 collaborators
18. Self-Hosted Git
● Free
o Remote ssh server with a git repo
o Gitolite - http://gitolite.com/
o Gitlab CE
● Non-free
o Gitlab - https://about.gitlab.com/
o Atlassian Stash -
https://www.atlassian.com/software/stash
19. More Reading
● “man git-<command>”
o man git-commit
● Git web site
o https://git-scm.com/
● Pro Git book
o https://git-scm.com/book