Version Control with Git for Beginners
-
Upload
bryanbibat -
Category
Technology
-
view
780 -
download
1
description
Transcript of Version Control with Git for Beginners
![Page 1: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/1.jpg)
Version Controlwith Git
![Page 2: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/2.jpg)
InstallationWindows: http://msysgit.github.io/
Mac: http://code.google.com/p/git-osx-installer
Linux (Debian/Ubuntu):apt-get install git-core gitk
Linux (Fedora):yum install git gitk
![Page 3: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/3.jpg)
Verify installationWindows: Open "Git Bash"
Mac/Linux: Open your terminal
To verify, run:$ git --version
![Page 4: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/4.jpg)
Yes, we are going to use the command line todayFeel free to use graphical interfaces after you learn the basics.
![Page 5: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/5.jpg)
Initial Setup$ git config --global user.name "Your Name"$ git config --global user.email "[email protected]"
Windows:
$ git config --global core.autocrlf true$ git config --global core.safecrlf true
Linux/Mac:
$ git config --global core.autocrlf input$ git config --global core.safecrlf true
![Page 6: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/6.jpg)
Version Control
![Page 7: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/7.jpg)
Version Controlaka Revision Control
![Page 8: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/8.jpg)
Version Controlaka Revision Control
aka How we do things in the Real World
![Page 9: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/9.jpg)
Sharing Code
![Page 10: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/10.jpg)
Working as a Team
![Page 11: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/11.jpg)
![Page 12: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/12.jpg)
Version Control
![Page 13: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/13.jpg)
Why Version Control?
![Page 14: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/14.jpg)
Reason #1:"Versioning"
![Page 15: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/15.jpg)
![Page 16: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/16.jpg)
![Page 17: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/17.jpg)
Wait a minute...
![Page 18: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/18.jpg)
![Page 19: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/19.jpg)
Finer-grained Control
![Page 20: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/20.jpg)
![Page 21: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/21.jpg)
Enough talk. Let's begin...
![Page 22: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/22.jpg)
Create your first repository
$ mkdir devcon-git101$ cd devcon-git101$ git init
![Page 23: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/23.jpg)
Create your first repository
$ mkdir devcon-git101$ cd devcon-git101$ git init
![Page 24: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/24.jpg)
Create your first repository
$ mkdir devcon-git101$ cd devcon-git101$ git init
Here we create a project folder
![Page 25: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/25.jpg)
Create your first repository
$ mkdir devcon-git101$ cd devcon-git101$ git init … Then we initialize it as a git repository.
![Page 26: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/26.jpg)
Create your first repository
$ mkdir devcon-git101$ cd devcon-git101$ git init … Then we initialize it as a git repository.
Git can now track the changes inside ourproject folder.
![Page 27: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/27.jpg)
Create your first commit
First create a file "hello.txt" containing:
Hello
Then run the following commands:
$ git add hello.txt$ git commit -m "Initial Commit"
![Page 28: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/28.jpg)
View the repository history
$ git log
(press q to exit)
![Page 29: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/29.jpg)
View the pretty repo history
$ git log --graph --pretty=oneline
(press q to exit)
![Page 30: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/30.jpg)
Ah, what the hell...
Windows/Linux:
$ gitk
Mac:
$ gitx
![Page 31: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/31.jpg)
Create your second commit
Modify "hello.txt" to add "world":
Hello World!
Then run the following commands:
$ git add hello.txt$ git commit -m "Make hello.txt more exciting"
![Page 32: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/32.jpg)
View the updated history
Windows/Linux:
$ gitk
Mac:
$ gitx
![Page 33: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/33.jpg)
What just happened?
![Page 34: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/34.jpg)
http://git-scm.com/book/en/Getting-Started-Git-Basics
![Page 35: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/35.jpg)
http://git-scm.com/book/en/Getting-Started-Git-Basics
git add
git commit
![Page 36: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/36.jpg)
Initial Commit6fba518
![Page 37: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/37.jpg)
Initial Commit6fba518
object nameaka object id, commit hash
● SHA-1 hash / checksum for verifying the integrity of the contents of the commit● Calculated based on file contents and metadata like last updated date i.e. yours
will be different
![Page 38: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/38.jpg)
Initial Commit6fba518
Make hello.txt more excitinge642771
![Page 39: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/39.jpg)
Initial Commit6fba518
Make hello.txt more excitinge642771
No, this is not a mistake;commits refer to their parent(s), not the other way around.
![Page 40: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/40.jpg)
Commit multiple files
Create a file "names.txt" containing:
Alice Bob Cindy
![Page 41: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/41.jpg)
Commit multiple files
Create a file "numbers.txt" containing:
3 9 16 12 8.2 4
![Page 42: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/42.jpg)
Commit multiple files
Run the following commands:
$ git add names.txt numbers.txt$ git commit -m "Create 2 files in a single commit"
![Page 43: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/43.jpg)
Initial Commit6fba518
Make hello.txt more excitinge642771
![Page 44: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/44.jpg)
Initial Commit1 file created
6fba518
Make hello.txt more exciting1 file modified
e642771
Create 2 files in a single commit2 files created
7c57165
Each commit deals with a set of files
![Page 45: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/45.jpg)
We've covered "Save", but before we move on to
"Load"...
![Page 46: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/46.jpg)
http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository
![Page 47: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/47.jpg)
File Status(all unmodified)
$ git status# On branch masternothing to commit, working directory clean
![Page 48: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/48.jpg)
File Status(untracked)
Create a file "animals.txt" containing:
Dogs Cats Mice
![Page 49: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/49.jpg)
File Status(untracked)
$ git status# On branch master# Untracked files:# (use "git add <file>..." to include in what will be committed)## animals.txtnothing added to commit but untracked files present (use "git add" to track)
![Page 50: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/50.jpg)
File Status(untracked and modified)
Modify "names.txt" to add "Janet":
Alice Bob Janet Cindy
![Page 51: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/51.jpg)
File Status(untracked and modified)
$ git status# On branch master# Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: names.txt## Untracked files:# (use "git add <file>..." to include in what will be committed)## animals.txtno changes added to commit (use "git add" and/or "git commit -a")
![Page 52: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/52.jpg)
File Status(untracked and staged)
$ git add names.txt$ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: names.txt## Untracked files:# (use "git add <file>..." to include in what will be committed)## animals.txt
![Page 53: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/53.jpg)
File Status(commit staged)
$ git commit -m "Add Janet"[master 5e545ed] Add Janet 1 file changed, 1 insertion(+)
$ git status# On branch master# Untracked files:# (use "git add <file>..." to include in what will be committed)## animals.txt
![Page 54: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/54.jpg)
Shortcuts
![Page 55: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/55.jpg)
Stage a folder
Modify "names.txt" to add "Ramon":
Alice Ramon Bob Janet Cindy
![Page 56: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/56.jpg)
Stage a folder
$ git add .$ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## new file: animals.txt# modified: names.txt#
![Page 57: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/57.jpg)
Unstage a file
$ git reset HEAD names.txtUnstaged changes after reset:M names.txt
$ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## new file: animals.txt## Changes not staged for commit:# (use "git add <file>..." to update what will be committed)# (use "git checkout -- <file>..." to discard changes in working directory)## modified: names.txt#
![Page 58: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/58.jpg)
Unmodify a file
$ git checkout -- names.txt
$ git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## new file: animals.txt#
![Page 59: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/59.jpg)
do it again...
Modify "names.txt" to add "Ramon":
Alice Ramon Bob Janet Cindy
![Page 60: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/60.jpg)
Stage and commit EVERYTHING
(except untracked files)
$ git commit -a -m "Commit unrelated changes.. DON'T DO THIS"[master 61f1cd8] Commit unrelated changes.. DON'T DO THIS 2 files changed, 4 insertions(+) create mode 100644 animals.txt
$ git status# On branch masternothing to commit, working directory clean
Note: using "-a" will also stage moved and renamed files.
![Page 61: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/61.jpg)
Amend last commit
$ git commit -m "Commit unrelated changes... DON'T DO THIS" --amend[master 3a0eac3] Commit unrelated changes... DON'T DO THIS 2 files changed, 4 insertions(+) create mode 100644 animals.txt
![Page 62: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/62.jpg)
On to "Load"...
![Page 63: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/63.jpg)
Initial Commit6fba518
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Commit unrelated changes... DON'T DO THIS3a0eac3
![Page 64: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/64.jpg)
Initial Commit6fba518
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Commit unrelated changes... DON'T DO THIS3a0eac3
HEAD
![Page 65: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/65.jpg)
Create a reverting commit
$ git revert HEAD --no-edit[master 2a1b52e] Revert "Commit unrelated changes... DON'T DO THIS" 2 files changed, 4 deletions(-) delete mode 100644 animals.txt
![Page 66: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/66.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Commit unrelated changes... DON'T DO THIS3a0eac3
HEAD
![Page 67: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/67.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Revert "Commit unrelated changes... DON'T DO THIS"
2a1b52e
HEAD
Commit unrelated changes... DON'T DO THIS3a0eac3
![Page 68: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/68.jpg)
Move HEAD to a commitdiscarding changes
$ git reset --hard 7c57165 HEAD is now at 7c57165 Create 2 files in a single commit
(You can use the first few characters of the object ID instead of the 40 characters)
![Page 69: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/69.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Revert "Commit unrelated changes... DON'T DO THIS"
2a1b52e
HEAD
Commit unrelated changes... DON'T DO THIS3a0eac3
![Page 70: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/70.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Revert "Commit unrelated changes... DON'T DO THIS"
2a1b52e
HEAD
Commit unrelated changes... DON'T DO THIS3a0eac3
![Page 71: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/71.jpg)
View history
$ git log --graph --pretty=format:'%h %s%d' --all* 7c57165 Create 2 files in a single commit (HEAD, master)* e642771 Make hello.txt more exciting* 6fba518 Initial Commit
or
$ gitk --all
![Page 72: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/72.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
HEAD
![Page 73: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/73.jpg)
Move HEAD to a commit
$ git reset --hard 2a1b52e HEAD is now at 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS"
![Page 74: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/74.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
HEAD
![Page 75: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/75.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Revert "Commit unrelated changes... DON'T DO THIS"
2a1b52e
HEAD
Commit unrelated changes... DON'T DO THIS3a0eac3
![Page 76: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/76.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Revert "Commit unrelated changes... DON'T DO THIS"
2a1b52e
HEAD
Commit unrelated changes... DON'T DO THIS3a0eac3
![Page 77: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/77.jpg)
Unreferenced commits will not show up in the history.
Coincidentally, we can use Tags to refer to a commit.
![Page 78: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/78.jpg)
Tagging
$ git tag tagging-demo
![Page 79: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/79.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Revert "Commit unrelated changes... DON'T DO THIS"
2a1b52e
HEAD
Commit unrelated changes... DON'T DO THIS3a0eac3
![Page 80: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/80.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Revert "Commit unrelated changes... DON'T DO THIS"
2a1b52e
HEAD
Commit unrelated changes... DON'T DO THIS3a0eac3
tagging-demo
![Page 81: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/81.jpg)
Going back...
$ git reset --hard 7c57165 HEAD is now at 7c57165 Create 2 files in a single commit
![Page 82: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/82.jpg)
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
Add Janet5e545ed
Revert "Commit unrelated changes... DON'T DO THIS"
2a1b52e
HEAD
Commit unrelated changes... DON'T DO THIS3a0eac3
tagging-demo
![Page 83: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/83.jpg)
View history
$ git log --graph --pretty=format:'%h %s%d' --all* 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS" (tagging-demo)* 3a0eac3 Commit unrelated changes... DON'T DO THIS* 5e545ed Add Janet* 7c57165 Create 2 files in a single commit (HEAD, master)* e642771 Make hello.txt more exciting* 6fba518 Initial Commit
or
$ gitk --all
![Page 84: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/84.jpg)
Wrapping up, tag current...
$ git tag end-part1
![Page 85: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/85.jpg)
...and unreference PDAF
$ git tag -d tagging-demoDeleted tag 'tagging-demo' (was 2a1b52e)
![Page 86: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/86.jpg)
Initial Commit6fba518
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
HEAD end-part1
![Page 87: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/87.jpg)
Best Practices
![Page 88: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/88.jpg)
Write good commit messages
You should be able to get an idea what changed and why just by looking at the commit messages
![Page 89: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/89.jpg)
Commit related changes
This would make it easier to roll back changes
![Page 90: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/90.jpg)
Commit often
![Page 91: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/91.jpg)
Do not commit generated files
E.g. compiled bytecode or executables, log files, temporary files, etc.
![Page 92: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/92.jpg)
Do not commit sensitive information
E.g. passwords, settings.You can, however, commit templates.
![Page 93: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/93.jpg)
Helpful Stuffthat we will not explain in detail...
![Page 95: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/95.jpg)
git stash
![Page 96: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/96.jpg)
git blame
![Page 97: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/97.jpg)
Summary of Commands
git init - initialize repository
git add - add files/folders to staging
git commit - commit files in staging
git status - view status of repository
git log / gitk - view history of repository
git revert - unstage files
git reset - move HEAD to another commit
git tag - tag a commit
![Page 98: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/98.jpg)
Summary of Command Variations
git commit -a - auto-stage all deleted, moved, modified
gitk --all / git log --all - include all branches, tags
git tag -d - delete tag
![Page 99: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/99.jpg)
Why Version Control?
![Page 100: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/100.jpg)
Reason #2:Backup
![Page 101: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/101.jpg)
Reason #2:Backup
![Page 102: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/102.jpg)
Reason #2:Collaboration
![Page 103: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/103.jpg)
If we were pressed for time...
● Register at GitHub● Learn git clone● Learn git push / git pull● Learn how to fix merge conflicts
![Page 104: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/104.jpg)
...but we're not, so let's first discuss something that will
help us later on.
![Page 105: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/105.jpg)
Branching
![Page 106: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/106.jpg)
File Status(all unmodified)
$ git status# On branch masternothing to commit, working directory clean
![Page 107: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/107.jpg)
File Status(all unmodified)
$ git status# On branch masternothing to commit, working directory clean
![Page 108: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/108.jpg)
Initial Commit6fba518
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
HEAD end-part1
![Page 109: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/109.jpg)
Initial Commit6fba518
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
master end-part1
HEAD
![Page 110: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/110.jpg)
Initial Commit6fba518
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
master end-part1
HEAD
in other version controlsystems, master is called
trunk
![Page 111: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/111.jpg)
Create a branch
$ git branch testing
![Page 112: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/112.jpg)
Initial Commit6fba518
Make hello.txt more excitinge642771
Create 2 files in a single commit7c57165
master end-part1
HEAD
![Page 113: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/113.jpg)
6fba518
e642771
7c57165
master
end-part1
HEAD
testing
![Page 114: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/114.jpg)
Switch to branch
$ git checkout testingSwitched to branch 'testing'
$ git status# On branch testingnothing to commit, working directory clean
![Page 115: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/115.jpg)
6fba518
e642771
7c57165
master
end-part1
HEAD
testing
![Page 116: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/116.jpg)
6fba518
e642771
7c57165
master
end-part1
HEAD
testing
![Page 117: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/117.jpg)
Commit to new branch
Modify "names.txt" to add "Eve":
Alice Bob Cindy Eve
![Page 118: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/118.jpg)
Commit to new branch
$ git commit -am "Add Eve"[testing cdd47c2] Add Eve 1 file changed, 1 insertion(+)
$ gitk
![Page 119: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/119.jpg)
6fba518
e642771
7c57165
master
end-part1
HEAD
testing
![Page 120: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/120.jpg)
6fba518
e642771
7c57165
master
end-part1
HEAD
testingcdd47c2
![Page 121: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/121.jpg)
6fba518
e642771
7c57165
master
end-part1
HEAD
testingcdd47c2
![Page 122: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/122.jpg)
Switch back to master
$ git checkout masterSwitched to branch 'master'
![Page 123: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/123.jpg)
6fba518
e642771
7c57165
master
end-part1
HEAD
testingcdd47c2
![Page 124: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/124.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2
HEAD
![Page 125: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/125.jpg)
Difference between log --all vs normal log
$ gitk
![Page 126: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/126.jpg)
6fba518
e642771
7c57165
master
end-part1
HEAD
![Page 127: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/127.jpg)
Difference between log --all vs normal log
$ gitk --all
![Page 128: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/128.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2
HEAD
![Page 129: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/129.jpg)
Commit to master
Modify "names.txt" to add "Billy":
Alice Billy Bob Cindy
$ git commit -am "Add Billy"[master cc3044c] Add Billy 1 file changed, 1 insertion(+)
![Page 130: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/130.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2
HEAD
![Page 131: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/131.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2
HEAD
cc3044c
![Page 132: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/132.jpg)
Shortcut: create and switch
$ git checkout -b testing2Switched to branch 'testing2'
![Page 133: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/133.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2
HEAD
cc3044c
![Page 134: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/134.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2cc3044c
HEAD
testing2
![Page 135: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/135.jpg)
Commit to testing2
Modify "names.txt" to add "Dave":
Alice Billy Bob Cindy Dave
$ git commit -am "Add Dave"[testing2 80414cf] Add Dave 1 file changed, 1 insertion(+)
![Page 136: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/136.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2cc3044c
HEAD
testing2
![Page 137: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/137.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2cc3044c
HEADtesting2
80414cf
![Page 138: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/138.jpg)
yay, mukha nang puno
![Page 139: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/139.jpg)
Go back to master
$ git checkout masterSwitched to branch 'master'
$ gitk --all
![Page 140: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/140.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2cc3044c
HEADtesting2
80414cf
![Page 141: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/141.jpg)
Merge another branch
$ git merge testingAuto-merging names.txtMerge made by the 'recursive' strategy. names.txt | 1 + 1 file changed, 1 insertion(+)
![Page 142: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/142.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2cc3044c
HEADtesting2
80414cf
![Page 143: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/143.jpg)
6fba518
e642771
7c57165
master
end-part1
testingcdd47c2cc3044c
HEADtesting2
80414cff56f4fa Merge branch 'testing'
![Page 144: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/144.jpg)
Merge Conflict
$ git merge testing2Auto-merging names.txtCONFLICT (content): Merge conflict in names.txtAutomatic merge failed; fix conflicts and then commit the result.
![Page 145: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/145.jpg)
Merge Conflict
Open names.txt:
Alice Billy Bob Cindy <<<<<<< HEAD Eve ======= Dave >>>>>>> testing2
![Page 146: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/146.jpg)
Merge Conflict
Open names.txt:
Alice Billy Bob Cindy <<<<<<< HEAD Eve ======= Dave >>>>>>> testing2
version from HEAD i.e master
![Page 147: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/147.jpg)
Merge Conflict
Open names.txt:
Alice Billy Bob Cindy <<<<<<< HEAD Eve ======= Dave >>>>>>> testing2
version from testing2
![Page 148: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/148.jpg)
Resolving Merge Conflict
Edit names.txt removing the markers:
Alice Billy Bob Cindy Dave Eve
![Page 149: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/149.jpg)
Resolving Merge Conflict
Commit the resolved merge conflict
$ git commit -am "Merge branch 'testing2' and fix conflict"[master 07e83b3] Merge branch 'testing2' and fix conflict
![Page 150: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/150.jpg)
e642771
7c57165
master
end-part1
testingcdd47c2cc3044c
HEADtesting2
80414cff56f4fa Merge branch 'testing'
![Page 151: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/151.jpg)
e642771
7c57165
master
end-part1
testingcdd47c2cc3044c
HEAD
testing2
80414cff56f4fa Merge branch 'testing'
07e83b3 Merge branch 'testing2' and fix conflict
![Page 152: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/152.jpg)
Another way to merge:Rebasing
![Page 153: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/153.jpg)
Working on two branches
$ git checkout -b merging-demoSwitched to a new branch 'merging-demo'
![Page 154: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/154.jpg)
Commit to merging-demo
Modify "names.txt" to remove "Alice":
Billy Bob Cindy Dave Eve
$ git commit -am "Remove Alice"[merging-demo 00b26cb] Remove Alice 1 file changed, 1 deletion(-)
![Page 155: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/155.jpg)
Commit to merging-demo
Modify "names.txt" to remove "Cindy":
Billy Bob Dave Eve
$ git commit -am "Remove Cindy"[merging-demo b115e79] Remove Cindy 1 file changed, 1 deletion(-)
![Page 156: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/156.jpg)
Switch back to master
$ git checkout masterSwitched to branch 'master'
![Page 157: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/157.jpg)
Commit to master
Modify "numbers.txt" to remove "8.2":
3 9 16 12 4
$ git commit -am "Remove 8.2"[master 0c1f192] Remove 8.2 1 file changed, 1 deletion(-)
![Page 158: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/158.jpg)
Commit to master
Modify "numbers.txt" to remove "9":
3 16 12 4
$ git commit -am "Remove 9"[master bc3583d] Remove 9 1 file changed, 1 deletion(-)
![Page 159: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/159.jpg)
master
b115e79
07e83b3
HEAD
merging-demo
00b26cb 0c1f192
bc3583d
![Page 160: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/160.jpg)
master
b115e79
07e83b3
HEAD
merging-demo
00b26cb 0c1f192
bc3583d
Merging
aff102e
![Page 161: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/161.jpg)
Rebasing
$ git rebase merging-demoFirst, rewinding head to replay your work on top of it...Applying: Remove 8.2Applying: Remove 9
![Page 162: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/162.jpg)
master
b115e79
07e83b3
HEAD
merging-demo
00b26cb 0c1f192
bc3583d
![Page 163: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/163.jpg)
master
b115e79
07e83b3
HEAD
merging-demo
00b26cb 0c1f192
bc3583d
Remove 8.2
Remove 9
![Page 164: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/164.jpg)
master
b115e79
07e83b3
HEAD
merging-demo
00b26cb
67b81ce
73dd819
Remove 8.2
Remove 9
![Page 165: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/165.jpg)
master
b115e79
07e83b3
HEAD
merging-demo
00b26cb
67b81ce
73dd819
Remove 8.2
Remove 9
![Page 166: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/166.jpg)
Later na lang yungmerge vs rebase
![Page 167: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/167.jpg)
Malapit na tayo mag-Github, but first...
![Page 168: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/168.jpg)
Remote Repositories
![Page 169: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/169.jpg)
Clone into another folder
$ cd ..
$ git clone devcon-git101 git101Cloning into 'git101'...done.
![Page 170: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/170.jpg)
Check the clone repo
$ cd git101
$ gitk
![Page 171: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/171.jpg)
merging-demo
master
HEAD
/devcon-git101
merging-demo
master
HEAD
/git101
![Page 172: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/172.jpg)
merging-demo
master
HEAD
/devcon-git101
merging-demo
master HEAD
/git101
remotes/origin/merging-demo
remotes/origin/master
![Page 173: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/173.jpg)
Show remote repos
$ git remoteorigin
![Page 174: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/174.jpg)
"origin" remote repo(default repo referring to the repo's origin)
$ git remote show origin* remote origin Fetch URL: c:/Users/user/devcon-git101 Push URL: c:/Users/user/devcon-git101 HEAD branch: master Remote branches: master tracked merging-demo tracked testing tracked testing2 tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date)
![Page 175: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/175.jpg)
master
HEAD
/devcon-git101
master HEAD
/git101
remotes/origin/master
![Page 176: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/176.jpg)
Synchronizing withRemote Repos
![Page 177: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/177.jpg)
Fetching demo
Go back to /devcon-git101 (either open a new terminal/Git Bash window) and modify "names.txt" to add Greg:
Billy Bob Dave Eve Greg $ git commit -am "Add Greg"[master cf5f902] Add Greg 1 file changed, 1 insertion(+)
![Page 178: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/178.jpg)
master
HEAD
/devcon-git101
master HEAD
/git101
remotes/origin/master
![Page 179: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/179.jpg)
master
HEAD
/devcon-git101
master HEAD
/git101
remotes/origin/master
![Page 180: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/180.jpg)
Fetching demo
Go back to git101 and fetch the changes:
$ cd ../git101
$ git fetchremote: Counting objects: 5, done.remote: Compressing objects: 100% (2/2), done.remote: Total 3 (delta 0), reused 0 (delta 0)Unpacking objects: 100% (3/3), done.From c:/Users/user/devcon-git101 73dd819..cf5f902 master -> origin/master
![Page 181: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/181.jpg)
master
HEAD
/devcon-git101
master HEAD
/git101
remotes/origin/master
![Page 182: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/182.jpg)
master
HEAD
/devcon-git101
master HEAD
/git101
remotes/origin/master
![Page 183: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/183.jpg)
Merge the fetched branch
$ git merge origin/masterUpdating 73dd819..cf5f902Fast-forward names.txt | 1 + 1 file changed, 1 insertion(+)
![Page 184: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/184.jpg)
master
HEAD
/devcon-git101
master HEAD
/git101
remotes/origin/master
![Page 185: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/185.jpg)
master
HEAD
/devcon-git101
master HEAD
/git101
remotes/origin/master
A fast-forward occurs when you merge a branch which has HEAD as an ancestor.In this case, only the references are affected.
![Page 186: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/186.jpg)
Shortcut
$ git fetch$ git merge origin/master
is equivalent to
$ git pull
if you're in master branch. We'll discuss more of this later.
![Page 187: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/187.jpg)
Now that we understand the basic idea behind remote repos,
let's proceed to Github...
Sign-up at https://github.com
![Page 188: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/188.jpg)
There are multiple ways to authenticate users in Git.
We'll discuss the most secure one: via SSH keys.
![Page 189: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/189.jpg)
Cryptography pasakalye...
![Page 190: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/190.jpg)
Authentication via Password
Client Server
![Page 191: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/191.jpg)
Authentication via Password
Client sendscredentials
Server verifies
username + password
passwordDB
![Page 192: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/192.jpg)
Authentication via Password
Client sendscredentials
Server verifies
username + password
passwordDB
can be interceptede.g. FTP
![Page 193: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/193.jpg)
Authentication via SSH Key(oversimplified)
Client has 2 "keys" Server
private key
public key
![Page 194: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/194.jpg)
Authentication via SSH Key(oversimplified)
Client has 2 "keys"Server has a list of
authorized keys
private key
public key
![Page 195: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/195.jpg)
Authentication via SSH Key(oversimplified)
Client has 2 "keys"Server has a list of
authorized keys
private key
public key
First, the public key must be sent to the server securely beforehand.
![Page 196: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/196.jpg)
Authentication via SSH Key(oversimplified)
ClientServer has a list of
authorized keys
private key
public key
Using the private key, client can create a package that can only be unlocked by the corresponding public key
and only that public key.
![Page 197: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/197.jpg)
Authentication via SSH Key(oversimplified)
ClientServer has a list of
authorized keys
private key
public key
Using the private key, client can create a package that can only be unlocked by the corresponding public key
and only that public key.
![Page 198: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/198.jpg)
Authentication via SSH Key(oversimplified)
ClientServer has a list of
authorized keys
private key
public key
Using the private key, client can create a package that can only be unlocked by the corresponding public key
and only that public key.
![Page 199: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/199.jpg)
Authentication via SSH Key(oversimplified)
ClientServer has a list of
authorized keys
private key
public key
Using the private key, client can create a package that can only be unlocked by the corresponding public key
and only that public key.
doesn't matter ifintercepted sincethey still need to
crack it.
![Page 200: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/200.jpg)
How to generate your SSH Keys:
https://help.github.com/articles/generating-ssh-keys
Also, follow the steps to add your public key to Github.
![Page 201: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/201.jpg)
If you want to be secure, use a passphrase.
However, if you're using Windows, you will need to enter it every time you run a git command that connects to Github.
![Page 202: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/202.jpg)
Fortunately, there is a workaround that will only require you to enter it
once per session.
http://stackoverflow.com/a/9011152
![Page 204: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/204.jpg)
Pushing devcon-git101Go back to devcon-git101 and push it to your new repo (use SSH url)
$ git remote add origin [email protected]:user/devcon-git101.git
$ git push -u origin masterWarning: Permanently added the RSA host key for IP address '192.30.252.130' to the list of known hosts.Enter passphrase for key '/c/Users/user/.ssh/id_rsa':Counting objects: 40, done.Delta compression using up to 4 threads.Compressing objects: 100% (24/24), done.Writing objects: 100% (40/40), 3.41 KiB, done.Total 40 (delta 3), reused 0 (delta 0)To [email protected]:user/devcon-git101.git * [new branch] master -> masterBranch master set up to track remote branch master from origin.
![Page 205: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/205.jpg)
git pushNote that "git push" only pushes a single branch.
If you want to push all branches you can use:
$ git push REMOTE --all
If you want to push all tags you can use:
$ git push REMOTE --tags
![Page 206: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/206.jpg)
Clone into another folder
$ cd ..
$ git clone [email protected]:user/devcon-git101.git github-git101Cloning into 'github-git101'...remote: Counting objects: 40, done.remote: Compressing objects: 100% (21/21), done.remote: Total 40 (delta 3), reused 40 (delta 3)Receiving objects: 100% (40/40), done.Resolving deltas: 100% (3/3), done.done.
![Page 207: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/207.jpg)
play time
With the cloned folder, you can now play around with certain collaboration scenarios. For example:
1. Make some changes in /devcon-git1012. Commit it via "git commit"3. Push it to the repo at Github via "git push"4. Go to /github-git101 and pull the changes via "git pull"
![Page 208: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/208.jpg)
Want to let someone else push to your repo?
Go to the repo Settings →Collaborators and add your friends.
![Page 209: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/209.jpg)
Push/Pull
You'll quickly notice that git push only allows fast-forward changes to be pushed.
In simpler terms, you cannot push until you pull the latest changes from the remote.
![Page 210: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/210.jpg)
pull + rebase
Want to get rid of the distracting merge commits whenever you pull when you have pending commits? Tell git to rebase instead of merging:
$ git pull --rebase origin master
![Page 211: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/211.jpg)
Best Practices
![Page 212: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/212.jpg)
merge vs rebase
The problem with rebase is that you can overwrite commits already on the remote repository and this can affect your team.
That said, people generally use rebase when working together on a single branch (e.g. git pull --rebase origin master) and merge when merging branches.
![Page 213: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/213.jpg)
Project Workflow
Here's the most basic workflow for working with with others through version control systems:
1. Double check if the project work e.g. compiles, pages load, etc.2. Stage and commit your changes.3. Before pushing, pull changes from the remote project repo. If there are no changes, skip to step 5.4. Resolve conflicts, if any, then go back to step 1.5. Push your changes.
![Page 214: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/214.jpg)
Communicate!Version control systems aims to improve communication between team members, not replace it.
Always consult with the other person whenever you encounter a merge conflict.
![Page 215: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/215.jpg)
Broken Builds
To repeat step 1:
1. Double check if the project work e.g. compiles, pages load, etc.
Broken builds are what we call published commits that have obvious critical, show-stopping bugs.
That said, it's better to delay pushing your commits to spend more time making sure that the project works rather than waste everyone's time.
![Page 216: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/216.jpg)
Work in Progress
Avoid publishing half-done work as it can lead to broken builds.
If you need to push those changes (e.g. you want a backup), put them in a branch then push that branch. Or consider using git stash.
![Page 217: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/217.jpg)
Helpful Stuffthat we will still not explain in detail...
![Page 218: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/218.jpg)
Graphical Git Tools
![Page 219: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/219.jpg)
Client - Server VCSvs
Distributed VCS
![Page 220: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/220.jpg)
Push-basedvs
Pull-based
![Page 221: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/221.jpg)
Backups
![Page 222: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/222.jpg)
GitHub as a Project Management Tool
![Page 223: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/223.jpg)
GitHub as a Project Management Tool forOpen Source Projects
![Page 224: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/224.jpg)
GitHub as a Portfolio
![Page 225: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/225.jpg)
Branches + Workflow
![Page 226: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/226.jpg)
Tagging + Deployment
![Page 227: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/227.jpg)
Free Private ReposSince Github is only free for public repos, you might want to look into the following to keep your source code private:
Assembla (https://www.assembla.com)- 1 private repo, limited to 3 collaborators
BitBucket (https://bitbucket.org/)- Unlimited private repos, limited to 5 collaborators
Github Educational Accounts (https://github.com/edu)- free accounts for students and teachers
![Page 228: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/228.jpg)
Summary of Commands
git branch - list, create, or delete branches
git checkout - checkout a branch or a path
git merge - merge two or more branches
git rebase - move commits to the end of a branch
git clone - make a local copy of a repository
git remote - list, create, or delete remote repos
git fetch - retrieve objects/changes from a repository
git pull - fetch + merge or rebase
git push - publish local commits to a remote
![Page 229: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/229.jpg)
Summary of Command Variations
git checkout -b - create and checkout branch
git remote add - add a new remote repository to track
git remote rm - remove remote repository
git pull --rebase - rebase instead of merge when pulling
![Page 230: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/230.jpg)
Commands that I use everyday
git pull --rebase
git add
git commit -am "blah blah"
gitk / git log / git status / git diff
git push
![Page 231: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/231.jpg)
Commands that I use less often
git clone
git remote add
git remote -v
git checkout <branch>
git rebase <branch> / git merge <branch>
git checkout -- <path>
git reset --hard <hash>
git revert
![Page 232: Version Control with Git for Beginners](https://reader034.fdocuments.us/reader034/viewer/2022052618/5549a170b4c9050c738b4ece/html5/thumbnails/232.jpg)
Thank You For Listening!