Download - Source control management
![Page 1: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/1.jpg)
With Git
SOURCE CONTROL MANAGEMENT
![Page 2: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/2.jpg)
BUT WAIT!
![Page 3: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/3.jpg)
Some EditorsSublime Text 2
Komodo Edit
Coda (Mac)
Text Wrangler (Mac)
PSPad (Win)
TextEdit (Win)
The ShellGit Bash
Terminal
ssh
TEXT EDITOR AND SHELL
![Page 4: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/4.jpg)
http://bit.ly/gdiscm
IMPORTANT PRE-CLASS LINKS
![Page 5: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/5.jpg)
# Level 1 Header (h1)
## Level 2 Header (h2)
##### Level 5 Header (h5)
Line breaks must have
two spaces at the end of the line.
Paragraphs are separated by a blank line.
Indent code blocks
with four spaces!
This is *italic*. (em)
This is **bold**. (strong)
This links to [Google](http://google.com)
* First Item
* Second Item
* Third Item
MARKDOWN QUICK GUIDE
![Page 6: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/6.jpg)
TRADITIONAL INTRObegins here…
![Page 8: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/8.jpg)
1.Basics of SCM2.Starting a Project
3.Branching and Experimentation
4.GitHub and Remotes5.Conflict Resolution
6.(Maybe) Using Submodules
TODAY’S PLAN
![Page 9: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/9.jpg)
WHAT IS SCM?aka “Revision Control”
![Page 10: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/10.jpg)
THE CURRENT STATE OF THINGS
![Page 11: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/11.jpg)
Revision control, also known as version control and source control is the
management of changes to documents, computer programs, large web sites, and other collections of information.
~ Wikipedia
WHAT IS SCM?
![Page 12: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/12.jpg)
• Resilience• Collaboration• Efficiency
• Accountability• Integration
ADVANTAGES OF SCM
![Page 13: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/13.jpg)
Working Copy
Production
Repository
Stage
Commit
Revert
Head
Branch
Master
Tag
Remote
Pull/Push
Merge
Conflict
Resolve
Hash
VOCABULARY
![Page 14: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/14.jpg)
THE GIT PROCESS
![Page 15: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/15.jpg)
THE GIT PROCESS
![Page 16: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/16.jpg)
THE GIT PROCESS
![Page 17: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/17.jpg)
THE GIT PROCESS
![Page 18: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/18.jpg)
THE GIT PROCESS
![Page 19: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/19.jpg)
SHELL BASICSThe Bare Minimum
![Page 20: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/20.jpg)
ls
ls -la
cd xx
cd ..
cd ~
cd /
mkdir
pwd -P
[letter][tab]
[up-arrow]
List the contents of a directory
List ALL the contents of a directory (hidden files, times, sizes)
Change to the directory “xx”
Change to the directory above this one
Change to your home directory
Change to the directory at the root of your computer
Make a directory
Show the full path of the current directory
Autocomplete or show all possibilities
Use the last command in your history
COMMANDS YOU SHOULD KNOW
![Page 21: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/21.jpg)
[Ctrl]+R
history
alias l="ls -la"
mv xx yy
rm xx
rmdir xx
Search for a previously used command
List the last 100 or so commands you used
Assign the command “l” to do “ls -la”
Rename/move the file “xx” as “yy”
Delete the file named “xx”
Delete the empty directory named “xx”
OTHER USEFUL COMMANDS
![Page 22: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/22.jpg)
Step 1• Change to the user
directory• Make a directory for this
class• Change to the class
directory• Create a directory called
“names”• Change to that directory
Step 2• Find the directory you
created in Finder/Explorer
• Create a file called “contributors.txt”
• Edit that file in your editor
• Add your name to the file
LET’S MAKE A FILE
Do not create the directory using
Finder/Explorer/your editor!
![Page 23: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/23.jpg)
HERE COMES THE FUN PARTStarting with git
![Page 24: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/24.jpg)
CENTRALIZEDVERSION CONTROL
My Computer
SomeCentral Server
![Page 25: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/25.jpg)
DISTRIBUTEDVERSION CONTROL
My Computer
![Page 26: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/26.jpg)
Configure Git Global Settings• Set your git username
git config --global user.name "github-user-name"
• Set your git email addressgit config --global user.email "github-email“
• Set your git editorMac: git config --global core.editor "nano"Windows: Use GitPad
Procedure• Change to the working directory• Initialize the repo
git init
CREATE A REPO
![Page 27: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/27.jpg)
![Page 28: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/28.jpg)
Files can have (in general) 4 states:
• Untracked• Tracked• Changed• Staged
GIT STATUS
![Page 29: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/29.jpg)
![Page 30: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/30.jpg)
GIT ADD/STAGE
We need a way to stage things to be committed.
Committing is an “all at once” action.
Procedure• Add the contributors.txt file to stage it.
git add contributors.txt
• Check the status of the working directory.git status
![Page 31: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/31.jpg)
![Page 32: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/32.jpg)
COMMIT
Commit changes to the repo.
All staged changes are committed at once.
Every commit is stored in the repo with a “hash”.
Procedure• Commit all staged changes
git commit
![Page 33: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/33.jpg)
![Page 34: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/34.jpg)
LET’S MAKE A CHANGE
Procedure• Get neighbor’s name and why they’re here• Add neighbor’s name to your editor (It’s still
open, right?)• Save the file with the added name• Check the status of your working directory
git status• Add the file to be staged
git add contributors.txt• commit the changes to your repo
git commit
![Page 35: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/35.jpg)
INTERLUDEIsn’t this exciting?
![Page 36: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/36.jpg)
Stash is the coolest feature ever.
Stash allows you to make other changes mid-change.
Procedure• While you still have changes… DO NOT COMMIT!• Instead, stash your changes
git stash
• Then make your change, add, and commit as normalgit add; git commit
• Then pop your change off the stashgit stash pop
GIT STASH
![Page 37: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/37.jpg)
INTERLUDEIsn’t this exciting?
![Page 38: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/38.jpg)
For when you ask yourself,
Hey, wait a minute, what did I change??
Procedure• Use Diff to see what is currently changed, but
not yet stagedgit diff
• Use Diff to see what is staged, but not yet committed
git diff –cached• Use Diff to see the differences between your
working copy and the last commitgit diff HEAD
GIT DIFF
![Page 39: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/39.jpg)
![Page 40: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/40.jpg)
![Page 41: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/41.jpg)
GIT LOG
Use the log to see what you and others have been adding to your repo.
Procedure• Use git log to see all changes in your current branch
git log
• Use --oneline to see each change in the log on one linegit log –oneline
• Use the hashes shown in the log to get the diff between two commits
git diff
![Page 42: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/42.jpg)
![Page 43: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/43.jpg)
INTERLUDEIsn’t this exciting?
![Page 44: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/44.jpg)
GIT REBASE
This is the “What the heck?” git command.
Rebase allows you to combine a bunch of commits into one that makes you look less like a freakish commit-crazy idiot.
Procedure• Use rebase to interactively select from the last 5 small
commits to combine into one big commit
git rebase –I HEAD~5
![Page 45: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/45.jpg)
![Page 46: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/46.jpg)
INTERLUDEIsn’t this exciting?
![Page 47: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/47.jpg)
Branching allows you to get experimental.
You can leave the state of master alone, and work solely on your branch.
Process• Create a new branch
git branch markdownlist
• Checkout the branch you want to work ongit checkout markdownlist
• OR Create a new branch and switch to using it all in one stepgit checkout -b markdownlist
• Then list the branches that are availablegit branchgit branch -v
BRANCHING
![Page 48: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/48.jpg)
![Page 49: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/49.jpg)
![Page 50: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/50.jpg)
ADD THAT LISTAsterisks aplenty
![Page 51: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/51.jpg)
SWITCHING BETWEEN BRANCHES
Branches track their own change history.
Switching between branches changes
only the unmodified, tracked files in your working copy.
Procedure• Check with branch you are on
git status
• Checkout the master branchgit checkout master
• Verify that you’re on the master branchgit status
![Page 52: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/52.jpg)
![Page 53: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/53.jpg)
REINTEGRATING BRANCHES
If the changes in a branch need to be copied into the master branch, they should be merged.
Merging is usually a scary word.
Procedure• Checkout the branch that the new code should be moved
togit checkout master
• Merge the branch into the current branchgit merge markdownlist
![Page 54: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/54.jpg)
![Page 55: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/55.jpg)
FEATURE BRANCHES
Development teams use Feature Branches for different purposes.
![Page 56: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/56.jpg)
![Page 57: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/57.jpg)
Tagging marks a specific commit with a name, and optionally annotates it.
Procedure• Use git tag to create a lightweight tag of the current
branch at HEADgit tag version1
• OR, Use the -a flag to annotate the taggit tag -a version 1 -m "My message"
• Use git show to see the commit of the taggit show version1
TAGGING
![Page 58: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/58.jpg)
![Page 59: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/59.jpg)
GITHUBA central git website
![Page 60: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/60.jpg)
SSH is the method Github uses to securely exchange data.
Public Keys are the means that Github uses to authenticate.
We must create a key pair to authenticate ourselves to Github.
SSH KEYPAIRS
![Page 61: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/61.jpg)
![Page 62: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/62.jpg)
![Page 63: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/63.jpg)
![Page 64: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/64.jpg)
CREATE A REPOOn Github!
![Page 65: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/65.jpg)
INITIALIZE A REPO FROM SCRATCH ON GITHUB
Using the instructions to get a repo from Github.
Procedure• Create the repo on Github• Follow the instructions to create an empty repo
git init; git add; git commit
• Connect the repo to Githubgit remote add origin
[email protected]:ringmaster/scm.git
• Push the repo to Githubgit push –u origin master
![Page 66: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/66.jpg)
![Page 67: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/67.jpg)
![Page 68: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/68.jpg)
![Page 69: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/69.jpg)
GIT PUSH
After you’ve completed a commit that you want to share,
push your commits to the remote repository.
Procedure• Finalize any commits (modified or untracked files won’t
be pushed!)• Execute git push on your repo
git push origin master
![Page 70: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/70.jpg)
![Page 71: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/71.jpg)
GIT PULL
When you want to update your working copy from the remote repository,
use git pull.
Procedure• Commit or stash any changes (git won’t let you pull over
modified files!)• Execute git pull on your repo
git pull origin master
![Page 72: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/72.jpg)
![Page 73: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/73.jpg)
ADDING A NEW REMOTE
Let’s try creating a new repo on Github for our contributors.txt file repo, and then pushing to that remote.
Procedure• Create a new repo on Github• Add the repo URL (ssh) as a remote on the existing
working copygit remote add origin
[email protected]:ringmaster/contrib.git
• Push the repo to Githubgit push –u origin master
![Page 74: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/74.jpg)
![Page 75: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/75.jpg)
CLONING EXISTING REPOSThis is the fun part
![Page 76: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/76.jpg)
CLONING
When there is an existing repo on Github that you would like to work on as your working copy, you clone it.
Procedure• Copy the git URL from the Github page (use the ssh
version)• Execute git clone where you want to create your new
working copygit clone [email protected]:ringmaster/fob.git
![Page 77: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/77.jpg)
![Page 78: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/78.jpg)
CONFLICT RESOLUTIONNo, this is the fun part
![Page 79: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/79.jpg)
https://github.com/ringmaster/gdiscm
HERE WE GO…
![Page 80: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/80.jpg)
• If you run blame, you’re most likely to find that you’re the one at fault.
• Commit whenever you feel like you’ve reached a point that you’re complete, even (especially) if you might
immediately rewrite the whole thing.
OWEN’S IMMUTABLE LAWS OF SCM
![Page 81: Source control management](https://reader036.vdocuments.us/reader036/viewer/2022062512/5549a1ebb4c905a6758b4ea5/html5/thumbnails/81.jpg)
http://git-scm.com/about
RESOURCES