Version Control
with Git
Installation
Windows: http://msysgit.github.io/
Mac: http://code.google.com/p/git-osx-installer
Linux (Debian/Ubuntu):
apt...
Verify installation
Windows: Open "Git Bash"
Mac/Linux: Open your terminal
To verify, run:

$ git --version
Yes, we are going to use
the command line today
Feel free to use graphical interfaces after you learn the basics.
Initial Setup
$ git config --global user.name "Your Name"
$ git config --global user.email "your_email@whatever.com"

Wind...
Version Control
Version Control
aka Revision Control
Version Control
aka Revision Control

aka How we do things in the Real World
Sharing Code
Working as a Team
Version Control
Why Version Control?
Reason #1:

"Versioning"
Wait a minute...
Finer-grained Control
Enough talk. Let's begin...
Create your first repository
$ mkdir devcon-git101
$ cd devcon-git101
$ git init
Create your first repository
$ mkdir devcon-git101
$ cd devcon-git101
$ git init
Create your first repository
$ mkdir devcon-git101
$ cd devcon-git101
$ git init

Here we create a project folder
Create your first repository
$ mkdir devcon-git101
$ cd devcon-git101
… Then we initialize it as a git repository.
$ git i...
Create your first repository
$ mkdir devcon-git101
$ cd devcon-git101
… Then we initialize it as a git repository.
$ git i...
Create your first commit
First create a file "hello.txt" containing:
Hello
Then run the following commands:
$ git add hell...
View the repository history
$ git log
(press q to exit)
View the pretty repo history
$ git log --graph --pretty=oneline
(press q to exit)
Ah, what the hell...
Windows/Linux:
$ gitk
Mac:
$ gitx
Create your second commit
Modify "hello.txt" to add "world":
Hello World!
Then run the following commands:
$ git add hello...
View the updated history
Windows/Linux:
$ gitk
Mac:
$ gitx
What just happened?
http://git-scm.com/book/en/Getting-Started-Git-Basics
git add
git commit

http://git-scm.com/book/en/Getting-Started-Git-Basics
6fba518

Initial Commit
6fba518

Initial Commit

object name
●
●

aka object id, commit hash
SHA-1 hash / checksum for verifying the integrity of ...
e642771

Make hello.txt more exciting

6fba518

Initial Commit
e642771

No, this is not a mistake;
commits refer to their
parent(s), not the other
way around.

Make hello.txt more excit...
Commit multiple files
Create a file "names.txt" containing:
Alice
Bob
Cindy
Commit multiple files
Create a file "numbers.txt" containing:
3
9
16
12
8.2
4
Commit multiple files
Run the following commands:
$ git add names.txt numbers.txt
$ git commit -m "Create 2 files in a sin...
e642771

Make hello.txt more exciting

6fba518

Initial Commit
Each commit deals with a set of files
7c57165

Create 2 files in a single commit
2 files created

e642771

Make hello.txt ...
We've covered "Save", but
before we move on to
"Load"...
http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository
File Status

(all unmodified)
$ git status
# On branch master
nothing to commit, working directory clean
File Status
(untracked)

Create a file "animals.txt" containing:
Dogs
Cats
Mice
File Status
(untracked)

$ git status
# On branch master
# Untracked files:
#
(use "git add <file>..." to include in
what ...
File Status

(untracked and modified)
Modify "names.txt" to add "Janet":
Alice
Bob
Janet
Cindy
File Status

(untracked and modified)
$ git status
# On branch master
# Changes not staged for commit:
#
(use "git add <fi...
File Status

(untracked and staged)
$ git add names.txt
$ git status
# On branch master
# Changes to be committed:
#
(use ...
File Status

(commit staged)
$ git commit -m "Add Janet"
[master 5e545ed] Add Janet
1 file changed, 1 insertion(+)
$ git s...
Shortcuts
Stage a folder
Modify "names.txt" to add "Ramon":
Alice
Ramon
Bob
Janet
Cindy
Stage a folder
$
$
#
#
#
#
#
#
#

git add .
git status
On branch master
Changes to be committed:
(use "git reset HEAD <fil...
Unstage a file
$ git reset HEAD names.txt
Unstaged changes after reset:
M
names.txt
$ git status
# On branch master
# Chan...
Unmodify a file
$ git checkout -- names.txt
$ git status
# On branch master
# Changes to be committed:
#
(use "git reset H...
do it again...
Modify "names.txt" to add "Ramon":
Alice
Ramon
Bob
Janet
Cindy
Stage and commit
EVERYTHING
(except untracked files)
$ git commit -a -m "Commit unrelated changes.. DON'T DO THIS"
[master...
Amend last commit
$ git commit -m "Commit unrelated changes... DON'T DO THIS" --amend
[master 3a0eac3] Commit unrelated ch...
On to "Load"...
3a0eac3

Commit unrelated changes... DON'T DO THIS

5e545ed

Add Janet

7c57165

Create 2 files in a single commit

e64277...
HEAD
3a0eac3

Commit unrelated changes... DON'T DO THIS

5e545ed

Add Janet

7c57165

Create 2 files in a single commit

e...
Create a reverting commit
$ git revert HEAD --no-edit
[master 2a1b52e] Revert "Commit unrelated changes... DON'T DO THIS"
...
HEAD
3a0eac3

Commit unrelated changes... DON'T DO THIS

5e545ed

Add Janet

7c57165

Create 2 files in a single commit

e...
HEAD
2a1b52e

Revert "Commit unrelated changes... DON'T
DO THIS"

3a0eac3

Commit unrelated changes... DON'T DO THIS

5e54...
Move HEAD to a commit
discarding changes
$ git reset --hard 7c57165
HEAD is now at 7c57165 Create 2 files in a single comm...
HEAD
2a1b52e

Revert "Commit unrelated changes... DON'T
DO THIS"

3a0eac3

Commit unrelated changes... DON'T DO THIS

5e54...
2a1b52e

Revert "Commit unrelated changes... DON'T
DO THIS"

3a0eac3

Commit unrelated changes... DON'T DO THIS

5e545ed

...
View history
$
*
*
*

git log
7c57165
e642771
6fba518

--graph --pretty=format:'%h %s%d' --all
Create 2 files in a single ...
HEAD
7c57165

Create 2 files in a single commit

e642771

Make hello.txt more exciting
Move HEAD to a commit
$ git reset --hard 2a1b52e
HEAD is now at 2a1b52e Revert "Commit unrelated changes... DON'T DO
THIS"
HEAD
7c57165

Create 2 files in a single commit

e642771

Make hello.txt more exciting
2a1b52e

Revert "Commit unrelated changes... DON'T
DO THIS"

3a0eac3

Commit unrelated changes... DON'T DO THIS

5e545ed

...
HEAD
2a1b52e

Revert "Commit unrelated changes... DON'T
DO THIS"

3a0eac3

Commit unrelated changes... DON'T DO THIS

5e54...
Unreferenced commits will
not show up in the history.
Coincidentally, we can use
Tags to refer to a commit.
Tagging
$ git tag tagging-demo
HEAD
2a1b52e

Revert "Commit unrelated changes... DON'T
DO THIS"

3a0eac3

Commit unrelated changes... DON'T DO THIS

5e54...
tagging-demo

HEAD
2a1b52e

Revert "Commit unrelated changes... DON'T
DO THIS"

3a0eac3

Commit unrelated changes... DON'T...
Going back...
$ git reset --hard 7c57165
HEAD is now at 7c57165 Create 2 files in a single commit
tagging-demo

2a1b52e

Revert "Commit unrelated changes... DON'T
DO THIS"

3a0eac3

Commit unrelated changes... DON'T DO T...
View history
$
*
*
*
*
*
*

git log
2a1b52e
3a0eac3
5e545ed
7c57165
e642771
6fba518

--graph --pretty=format:'%h %s%d' --a...
Wrapping up, tag current...
$ git tag end-part1
...and unreference PDAF
$ git tag -d tagging-demo
Deleted tag 'tagging-demo' (was 2a1b52e)
end-part1

HEAD

7c57165

Create 2 files in a single commit

e642771

Make hello.txt more exciting

6fba518

Initial Commi...
Best Practices
Write good commit
messages
You should be able to get an idea what changed
and why just by looking at the commit messages
Commit related changes
This would make it easier to roll back changes
Commit often
Do not commit generated files
E.g. compiled bytecode or executables, log files,
temporary files, etc.
Do not commit sensitive
information
E.g. passwords, settings.
You can, however, commit templates.
Helpful Stuff
that we will not explain in detail...
.gitignore
https://github.com/github/gitignore
git stash
git blame
Summary of Commands
git init - initialize repository
git add - add files/folders to staging
git commit - commit files in s...
Summary of Command
Variations
git commit -a
- auto-stage all deleted, moved, modified
gitk --all / git log --all
- include...
Why Version Control?
Reason #2:

Backup
Reason #2:

Backup
Reason #2:

Collaboration
If we were pressed for time...
Register at GitHub
● Learn git clone
● Learn git push / git pull
●
Learn how to fix merge c...
...but we're not, so let's first
discuss something that will
help us later on.
Branching
File Status

(all unmodified)
$ git status
# On branch master
nothing to commit, working directory clean
File Status

(all unmodified)
$ git status
# On branch master
nothing to commit, working directory clean
end-part1

HEAD

7c57165

Create 2 files in a single commit

e642771

Make hello.txt more exciting

6fba518

Initial Commi...
HEAD

end-part1

master

7c57165

Create 2 files in a single commit

e642771

Make hello.txt more exciting

6fba518

Initi...
HEAD

end-part1

master
in other version control
systems, master is called
trunk

7c57165

Create 2 files in a single comm...
Create a branch
$ git branch testing
HEAD

end-part1

master

7c57165

Create 2 files in a single commit

e642771

Make hello.txt more exciting

6fba518

Initi...
HEAD

master

testing
7c57165

e642771

6fba518

end-part1
Switch to branch
$ git checkout testing
Switched to branch 'testing'
$ git status
# On branch testing
nothing to commit, w...
HEAD

master

testing
7c57165

e642771

6fba518

end-part1
HEAD

master

testing
7c57165

e642771

6fba518

end-part1
Commit to new branch
Modify "names.txt" to add "Eve":
Alice
Bob
Cindy
Eve
Commit to new branch
$ git commit -am "Add Eve"
[testing cdd47c2] Add Eve
1 file changed, 1 insertion(+)
$ gitk
HEAD

master

testing
7c57165

e642771

6fba518

end-part1
HEAD

cdd47c2

testing

master

7c57165

e642771

6fba518

end-part1
HEAD

cdd47c2

master

7c57165

e642771

6fba518

end-part1

testing
Switch back to master
$ git checkout master
Switched to branch 'master'
HEAD

cdd47c2

master

7c57165

e642771

6fba518

end-part1

testing
HEAD
cdd47c2

master

7c57165

e642771

6fba518

end-part1

testing
Difference between log --all
vs normal log
$ gitk
HEAD

master

7c57165

e642771

6fba518

end-part1
Difference between log --all
vs normal log
$ gitk --all
HEAD
cdd47c2

master

7c57165

e642771

6fba518

end-part1

testing
Commit to master
Modify "names.txt" to add "Billy":
Alice
Billy
Bob
Cindy
$ git commit -am "Add Billy"
[master cc3044c] Ad...
HEAD
cdd47c2

master

7c57165

e642771

6fba518

end-part1

testing
HEAD

master

cc3044c

7c57165

e642771

6fba518

cdd47c2

end-part1

testing
Shortcut: create and switch
$ git checkout -b testing2
Switched to branch 'testing2'
HEAD

master

cc3044c

7c57165

e642771

6fba518

cdd47c2

end-part1

testing
HEAD

master

testing2

cc3044c

7c57165

e642771

6fba518

cdd47c2

end-part1

testing
Commit to testing2
Modify "names.txt" to add "Dave":
Alice
Billy
Bob
Cindy
Dave
$ git commit -am "Add Dave"
[testing2 8041...
HEAD

master

testing2

cc3044c

7c57165

e642771

6fba518

cdd47c2

end-part1

testing
testing2

HEAD

80414cf

master

cc3044c

7c57165

e642771

6fba518

cdd47c2

end-part1

testing
yay, mukha nang puno
Go back to master
$ git checkout master
Switched to branch 'master'
$ gitk --all
testing2

HEAD

80414cf

master

cc3044c

7c57165

e642771

6fba518

cdd47c2

end-part1

testing
Merge another branch
$ git merge testing
Auto-merging names.txt
Merge made by the 'recursive' strategy.
names.txt | 1 +
1 ...
testing2

HEAD

80414cf

master

cc3044c

7c57165

e642771

6fba518

cdd47c2

end-part1

testing
master

testing2

80414cf

f56f4fa

cc3044c

7c57165

e642771

6fba518

HEAD

Merge branch 'testing'

cdd47c2

end-part1

...
Merge Conflict
$ git merge testing2
Auto-merging names.txt
CONFLICT (content): Merge conflict in names.txt
Automatic merge...
Merge Conflict
Open names.txt:
Alice
Billy
Bob
Cindy
<<<<<<< HEAD
Eve
=======
Dave
>>>>>>> testing2
Merge Conflict
Open names.txt:
Alice
Billy
Bob
Cindy
<<<<<<< HEAD
Eve
=======
Dave
>>>>>>> testing2

version from HEAD i.e...
Merge Conflict
Open names.txt:
Alice
Billy
Bob
Cindy
<<<<<<< HEAD
Eve
=======
Dave
>>>>>>> testing2

version from testing2
Resolving Merge Conflict
Edit names.txt removing the markers:
Alice
Billy
Bob
Cindy
Dave
Eve
Resolving Merge Conflict
Commit the resolved merge conflict
$ git commit -am "Merge branch 'testing2' and fix
conflict"
[m...
master

testing2

80414cf

f56f4fa

cc3044c

7c57165

e642771

HEAD

Merge branch 'testing'

cdd47c2

end-part1

testing
master

HEAD

07e83b3

Merge branch 'testing2' and fix conflict

f56f4fa

Merge branch 'testing'

testing2

80414cf

cc304...
Another way to merge:
Rebasing
Working on two branches
$ git checkout -b merging-demo
Switched to a new branch 'merging-demo'
Commit to merging-demo
Modify "names.txt" to remove "Alice":
Billy
Bob
Cindy
Dave
Eve
$ git commit -am "Remove Alice"
[mer...
Commit to merging-demo
Modify "names.txt" to remove "Cindy":
Billy
Bob
Dave
Eve
$ git commit -am "Remove Cindy"
[merging-d...
Switch back to master
$ git checkout master
Switched to branch 'master'
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...
Commit to master
Modify "numbers.txt" to remove "9":
3
16
12
4
$ git commit -am "Remove 9"
[master bc3583d] Remove 9
1 fil...
merging-demo
master
b115e79

00b26cb

bc3583d

0c1f192

07e83b3

HEAD
Merging
master
merging-demo
aff102e

b115e79

00b26cb

bc3583d

0c1f192

07e83b3

HEAD
Rebasing
$ git rebase merging-demo
First, rewinding head to replay your work on
top of it...
Applying: Remove 8.2
Applying...
merging-demo
master
b115e79

00b26cb

bc3583d

0c1f192

07e83b3

HEAD
merging-demo
master

b115e79

00b26cb

HEAD

bc3583d

Remove 9

0c1f192

Remove 8.2

07e83b3
master

73dd819

Remove 9

67b81ce

Remove 8.2

merging-demo

b115e79

00b26cb

07e83b3

HEAD
master

73dd819

67b81ce

merging-demo

Remove 9

Remove 8.2

b115e79

00b26cb

07e83b3

HEAD
Later na lang yung
merge vs rebase
Malapit na tayo mag-Github,
but first...
Remote Repositories
Clone into another folder
$ cd ..
$ git clone devcon-git101 git101
Cloning into 'git101'...
done.
Check the clone repo
$ cd git101
$ gitk
HEAD

HEAD

master

master

merging-demo

/devcon-git101

merging-demo

/git101
remotes/origin/
master

HEAD

master

master
remotes/origin/
merging-demo

merging-demo

/devcon-git101

merging-demo

/gi...
Show remote repos
$ git remote
origin
"origin" remote repo
(default repo referring to the repo's origin)
$ git remote show origin
* remote origin
Fetch URL: c:/...
remotes/origin/
master

HEAD

master

/devcon-git101

master

/git101

HEAD
Synchronizing with
Remote Repos
Fetching demo
Go back to /devcon-git101 (either open a new terminal/Git Bash
window) and modify "names.txt" to add Greg:
B...
remotes/origin/
master

HEAD

master

/devcon-git101

master

/git101

HEAD
HEAD
remotes/origin/
master

master

master

/devcon-git101

/git101

HEAD
Fetching demo
Go back to git101 and fetch the changes:
$ cd ../git101
$ git fetch
remote: Counting objects: 5, done.
remot...
HEAD
remotes/origin/
master

master

master

/devcon-git101

/git101

HEAD
remotes/origin/
master

HEAD

master
master

/devcon-git101

/git101

HEAD
Merge the fetched branch
$ git merge origin/master
Updating 73dd819..cf5f902
Fast-forward
names.txt | 1 +
1 file changed, ...
remotes/origin/
master

HEAD

master
master

/devcon-git101

/git101

HEAD
A fast-forward occurs when you merge a
branch which has HEAD as an ancestor.
In this case, only the references are affecte...
Shortcut
$ git fetch
$ git merge origin/master
is equivalent to
$ git pull
if you're in master branch.
We'll discuss more ...
Now that we understand the
basic idea behind remote repos,
let's proceed to Github...
Sign-up at https://github.com
There are multiple ways to
authenticate users in Git.
We'll discuss the most secure
one: via SSH keys.
Cryptography pasakalye...
Authentication via Password

Client

Server
Authentication via Password

username + password

Client sends
credentials

Server verifies

password
DB
Authentication via Password

username + password

Client sends
credentials

can be intercepted
e.g. FTP

Server verifies

...
Authentication via SSH Key
(oversimplified)

Client has 2 "keys"

private key
public key

Server
Authentication via SSH Key
(oversimplified)

Client has 2 "keys"

private key
public key

Server has a list of
authorized ...
Authentication via SSH Key
(oversimplified)
First, the public key must be sent to the server securely beforehand.

Client ...
Authentication via SSH Key
(oversimplified)
Using the private key, client can create a package that
can only be unlocked b...
Authentication via SSH Key
(oversimplified)
Using the private key, client can create a package that
can only be unlocked b...
Authentication via SSH Key
(oversimplified)
Using the private key, client can create a package that
can only be unlocked b...
Authentication via SSH Key
(oversimplified)
Using the private key, client can create a package that
can only be unlocked b...
How to generate your SSH Keys:
https://help.github.com/articles/generating-ssh-keys

Also, follow the steps to add your pu...
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...
Fortunately, there is a workaround
that will only require you to enter it
once per session.
http://stackoverflow.com/a/901...
Create a repo in Github for
devcon-git101
https://github.com/new
Pushing devcon-git101
Go back to devcon-git101 and push it to your new repo (use SSH url)
$ git remote add origin git@gith...
git push
Note that "git push" only pushes a single branch.
If you want to push all branches you can use:

$ git push REMOT...
Clone into another folder
$ cd ..
$ git clone git@github.com:user/devcon-git101.git github-git101
Cloning into 'github-git...
play time
With the cloned folder, you can now play around with certain
collaboration scenarios. For example:
1. Make some ...
Want to let someone else push to
your repo?
Go to the repo Settings →
Collaborators and add your friends.
Push/Pull
You'll quickly notice that git push only allows
fast-forward changes to be pushed.
In simpler terms, you cannot ...
pull + rebase
Want to get rid of the distracting merge commits
whenever you pull when you have pending
commits? Tell git t...
Best Practices
merge vs rebase
The problem with rebase is that you can overwrite
commits already on the remote repository and this can
af...
Project Workflow
Here's the most basic workflow for working with with others
through version control systems:
1. Double ch...
Communicate!
Version control systems aims to improve communication
between team members, not replace it.

Always consult w...
Broken Builds
To repeat step 1:
1. Double check if the project work e.g. compiles, pages load, etc.
Broken builds are what...
Work in Progress
Avoid publishing half-done work as it can lead to
broken builds.
If you need to push those changes (e.g. ...
Helpful Stuff
that we will still not explain in detail...
Graphical Git Tools
Client - Server VCS
vs
Distributed VCS
Push-based
vs
Pull-based
Backups
GitHub as a Project
Management Tool
GitHub as a Project
Management Tool for
Open Source Projects
GitHub as a Portfolio
Branches + Workflow
Tagging + Deployment
Free Private Repos
Since Github is only free for public repos, you might want to
look into the following to keep your sour...
Summary of Commands
git branch - list, create, or delete branches
git checkout - checkout a branch or a path
git merge - m...
Summary of Command
Variations
git checkout -b
- create and checkout branch
git remote add
- add a new remote repository to...
Commands that I use
everyday
git pull --rebase
git add
git commit -am "blah blah"
gitk / git log / git status / git diff
g...
Commands that I use less
often
git clone
git remote add
git remote -v
git checkout <branch>
git rebase <branch> / git merg...
Thank You For Listening!
Version Control with Git for Beginners
Version Control with Git for Beginners
Version Control with Git for Beginners
Version Control with Git for Beginners
Version Control with Git for Beginners
Upcoming SlideShare
Loading in...5
×

Version Control with Git for Beginners

848

Published on

Version Control with Git for Beginners

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
848
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
15
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Version Control with Git for Beginners

  1. 1. Version Control with Git
  2. 2. Installation Windows: 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
  3. 3. Verify installation Windows: Open "Git Bash" Mac/Linux: Open your terminal To verify, run: $ git --version
  4. 4. Yes, we are going to use the command line today Feel free to use graphical interfaces after you learn the basics.
  5. 5. Initial Setup $ git config --global user.name "Your Name" $ git config --global user.email "your_email@whatever.com" 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
  6. 6. Version Control
  7. 7. Version Control aka Revision Control
  8. 8. Version Control aka Revision Control aka How we do things in the Real World
  9. 9. Sharing Code
  10. 10. Working as a Team
  11. 11. Version Control
  12. 12. Why Version Control?
  13. 13. Reason #1: "Versioning"
  14. 14. Wait a minute...
  15. 15. Finer-grained Control
  16. 16. Enough talk. Let's begin...
  17. 17. Create your first repository $ mkdir devcon-git101 $ cd devcon-git101 $ git init
  18. 18. Create your first repository $ mkdir devcon-git101 $ cd devcon-git101 $ git init
  19. 19. Create your first repository $ mkdir devcon-git101 $ cd devcon-git101 $ git init Here we create a project folder
  20. 20. Create your first repository $ mkdir devcon-git101 $ cd devcon-git101 … Then we initialize it as a git repository. $ git init
  21. 21. Create your first repository $ mkdir devcon-git101 $ cd devcon-git101 … Then we initialize it as a git repository. $ git init Git can now track the changes inside our project folder.
  22. 22. 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"
  23. 23. View the repository history $ git log (press q to exit)
  24. 24. View the pretty repo history $ git log --graph --pretty=oneline (press q to exit)
  25. 25. Ah, what the hell... Windows/Linux: $ gitk Mac: $ gitx
  26. 26. 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"
  27. 27. View the updated history Windows/Linux: $ gitk Mac: $ gitx
  28. 28. What just happened?
  29. 29. http://git-scm.com/book/en/Getting-Started-Git-Basics
  30. 30. git add git commit http://git-scm.com/book/en/Getting-Started-Git-Basics
  31. 31. 6fba518 Initial Commit
  32. 32. 6fba518 Initial Commit object name ● ● aka 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
  33. 33. e642771 Make hello.txt more exciting 6fba518 Initial Commit
  34. 34. e642771 No, this is not a mistake; commits refer to their parent(s), not the other way around. Make hello.txt more exciting 6fba518 Initial Commit
  35. 35. Commit multiple files Create a file "names.txt" containing: Alice Bob Cindy
  36. 36. Commit multiple files Create a file "numbers.txt" containing: 3 9 16 12 8.2 4
  37. 37. Commit multiple files Run the following commands: $ git add names.txt numbers.txt $ git commit -m "Create 2 files in a single commit"
  38. 38. e642771 Make hello.txt more exciting 6fba518 Initial Commit
  39. 39. Each commit deals with a set of files 7c57165 Create 2 files in a single commit 2 files created e642771 Make hello.txt more exciting 1 file modified 6fba518 Initial Commit 1 file created
  40. 40. We've covered "Save", but before we move on to "Load"...
  41. 41. http://git-scm.com/book/en/Git-Basics-Recording-Changes-to-the-Repository
  42. 42. File Status (all unmodified) $ git status # On branch master nothing to commit, working directory clean
  43. 43. File Status (untracked) Create a file "animals.txt" containing: Dogs Cats Mice
  44. 44. File Status (untracked) $ git status # On branch master # Untracked files: # (use "git add <file>..." to include in what will be committed) # # animals.txt nothing added to commit but untracked files present (use "git add" to track)
  45. 45. File Status (untracked and modified) Modify "names.txt" to add "Janet": Alice Bob Janet Cindy
  46. 46. 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.txt no changes added to commit (use "git add" and/or "git commit -a")
  47. 47. 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
  48. 48. 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
  49. 49. Shortcuts
  50. 50. Stage a folder Modify "names.txt" to add "Ramon": Alice Ramon Bob Janet Cindy
  51. 51. Stage a folder $ $ # # # # # # # git add . git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: modified: animals.txt names.txt
  52. 52. Unstage a file $ git reset HEAD names.txt Unstaged 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 #
  53. 53. 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 #
  54. 54. do it again... Modify "names.txt" to add "Ramon": Alice Ramon Bob Janet Cindy
  55. 55. 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 master nothing to commit, working directory clean Note: using "-a" will also stage moved and renamed files.
  56. 56. 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
  57. 57. On to "Load"...
  58. 58. 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting 6fba518 Initial Commit
  59. 59. HEAD 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting 6fba518 Initial Commit
  60. 60. 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
  61. 61. HEAD 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting
  62. 62. HEAD 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS" 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting
  63. 63. Move HEAD to a commit discarding 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)
  64. 64. HEAD 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS" 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting
  65. 65. 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS" 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting HEAD
  66. 66. View history $ * * * git log 7c57165 e642771 6fba518 --graph --pretty=format:'%h %s%d' --all Create 2 files in a single commit (HEAD, master) Make hello.txt more exciting Initial Commit or $ gitk --all
  67. 67. HEAD 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting
  68. 68. Move HEAD to a commit $ git reset --hard 2a1b52e HEAD is now at 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS"
  69. 69. HEAD 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting
  70. 70. 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS" 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting HEAD
  71. 71. HEAD 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS" 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting
  72. 72. Unreferenced commits will not show up in the history. Coincidentally, we can use Tags to refer to a commit.
  73. 73. Tagging $ git tag tagging-demo
  74. 74. HEAD 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS" 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting
  75. 75. tagging-demo HEAD 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS" 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting
  76. 76. Going back... $ git reset --hard 7c57165 HEAD is now at 7c57165 Create 2 files in a single commit
  77. 77. tagging-demo 2a1b52e Revert "Commit unrelated changes... DON'T DO THIS" 3a0eac3 Commit unrelated changes... DON'T DO THIS 5e545ed Add Janet 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting HEAD
  78. 78. View history $ * * * * * * git log 2a1b52e 3a0eac3 5e545ed 7c57165 e642771 6fba518 --graph --pretty=format:'%h %s%d' --all Revert "Commit unrelated changes... DON'T DO THIS" (tagging-demo) Commit unrelated changes... DON'T DO THIS Add Janet Create 2 files in a single commit (HEAD, master) Make hello.txt more exciting Initial Commit or $ gitk --all
  79. 79. Wrapping up, tag current... $ git tag end-part1
  80. 80. ...and unreference PDAF $ git tag -d tagging-demo Deleted tag 'tagging-demo' (was 2a1b52e)
  81. 81. end-part1 HEAD 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting 6fba518 Initial Commit
  82. 82. Best Practices
  83. 83. Write good commit messages You should be able to get an idea what changed and why just by looking at the commit messages
  84. 84. Commit related changes This would make it easier to roll back changes
  85. 85. Commit often
  86. 86. Do not commit generated files E.g. compiled bytecode or executables, log files, temporary files, etc.
  87. 87. Do not commit sensitive information E.g. passwords, settings. You can, however, commit templates.
  88. 88. Helpful Stuff that we will not explain in detail...
  89. 89. .gitignore https://github.com/github/gitignore
  90. 90. git stash
  91. 91. git blame
  92. 92. 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
  93. 93. 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
  94. 94. Why Version Control?
  95. 95. Reason #2: Backup
  96. 96. Reason #2: Backup
  97. 97. Reason #2: Collaboration
  98. 98. If we were pressed for time... Register at GitHub ● Learn git clone ● Learn git push / git pull ● Learn how to fix merge conflicts ●
  99. 99. ...but we're not, so let's first discuss something that will help us later on.
  100. 100. Branching
  101. 101. File Status (all unmodified) $ git status # On branch master nothing to commit, working directory clean
  102. 102. File Status (all unmodified) $ git status # On branch master nothing to commit, working directory clean
  103. 103. end-part1 HEAD 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting 6fba518 Initial Commit
  104. 104. HEAD end-part1 master 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting 6fba518 Initial Commit
  105. 105. HEAD end-part1 master in other version control systems, master is called trunk 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting 6fba518 Initial Commit
  106. 106. Create a branch $ git branch testing
  107. 107. HEAD end-part1 master 7c57165 Create 2 files in a single commit e642771 Make hello.txt more exciting 6fba518 Initial Commit
  108. 108. HEAD master testing 7c57165 e642771 6fba518 end-part1
  109. 109. Switch to branch $ git checkout testing Switched to branch 'testing' $ git status # On branch testing nothing to commit, working directory clean
  110. 110. HEAD master testing 7c57165 e642771 6fba518 end-part1
  111. 111. HEAD master testing 7c57165 e642771 6fba518 end-part1
  112. 112. Commit to new branch Modify "names.txt" to add "Eve": Alice Bob Cindy Eve
  113. 113. Commit to new branch $ git commit -am "Add Eve" [testing cdd47c2] Add Eve 1 file changed, 1 insertion(+) $ gitk
  114. 114. HEAD master testing 7c57165 e642771 6fba518 end-part1
  115. 115. HEAD cdd47c2 testing master 7c57165 e642771 6fba518 end-part1
  116. 116. HEAD cdd47c2 master 7c57165 e642771 6fba518 end-part1 testing
  117. 117. Switch back to master $ git checkout master Switched to branch 'master'
  118. 118. HEAD cdd47c2 master 7c57165 e642771 6fba518 end-part1 testing
  119. 119. HEAD cdd47c2 master 7c57165 e642771 6fba518 end-part1 testing
  120. 120. Difference between log --all vs normal log $ gitk
  121. 121. HEAD master 7c57165 e642771 6fba518 end-part1
  122. 122. Difference between log --all vs normal log $ gitk --all
  123. 123. HEAD cdd47c2 master 7c57165 e642771 6fba518 end-part1 testing
  124. 124. 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(+)
  125. 125. HEAD cdd47c2 master 7c57165 e642771 6fba518 end-part1 testing
  126. 126. HEAD master cc3044c 7c57165 e642771 6fba518 cdd47c2 end-part1 testing
  127. 127. Shortcut: create and switch $ git checkout -b testing2 Switched to branch 'testing2'
  128. 128. HEAD master cc3044c 7c57165 e642771 6fba518 cdd47c2 end-part1 testing
  129. 129. HEAD master testing2 cc3044c 7c57165 e642771 6fba518 cdd47c2 end-part1 testing
  130. 130. 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(+)
  131. 131. HEAD master testing2 cc3044c 7c57165 e642771 6fba518 cdd47c2 end-part1 testing
  132. 132. testing2 HEAD 80414cf master cc3044c 7c57165 e642771 6fba518 cdd47c2 end-part1 testing
  133. 133. yay, mukha nang puno
  134. 134. Go back to master $ git checkout master Switched to branch 'master' $ gitk --all
  135. 135. testing2 HEAD 80414cf master cc3044c 7c57165 e642771 6fba518 cdd47c2 end-part1 testing
  136. 136. Merge another branch $ git merge testing Auto-merging names.txt Merge made by the 'recursive' strategy. names.txt | 1 + 1 file changed, 1 insertion(+)
  137. 137. testing2 HEAD 80414cf master cc3044c 7c57165 e642771 6fba518 cdd47c2 end-part1 testing
  138. 138. master testing2 80414cf f56f4fa cc3044c 7c57165 e642771 6fba518 HEAD Merge branch 'testing' cdd47c2 end-part1 testing
  139. 139. Merge Conflict $ git merge testing2 Auto-merging names.txt CONFLICT (content): Merge conflict in names.txt Automatic merge failed; fix conflicts and then commit the result.
  140. 140. Merge Conflict Open names.txt: Alice Billy Bob Cindy <<<<<<< HEAD Eve ======= Dave >>>>>>> testing2
  141. 141. Merge Conflict Open names.txt: Alice Billy Bob Cindy <<<<<<< HEAD Eve ======= Dave >>>>>>> testing2 version from HEAD i.e master
  142. 142. Merge Conflict Open names.txt: Alice Billy Bob Cindy <<<<<<< HEAD Eve ======= Dave >>>>>>> testing2 version from testing2
  143. 143. Resolving Merge Conflict Edit names.txt removing the markers: Alice Billy Bob Cindy Dave Eve
  144. 144. 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
  145. 145. master testing2 80414cf f56f4fa cc3044c 7c57165 e642771 HEAD Merge branch 'testing' cdd47c2 end-part1 testing
  146. 146. master HEAD 07e83b3 Merge branch 'testing2' and fix conflict f56f4fa Merge branch 'testing' testing2 80414cf cc3044c 7c57165 e642771 cdd47c2 end-part1 testing
  147. 147. Another way to merge: Rebasing
  148. 148. Working on two branches $ git checkout -b merging-demo Switched to a new branch 'merging-demo'
  149. 149. 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(-)
  150. 150. 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(-)
  151. 151. Switch back to master $ git checkout master Switched to branch 'master'
  152. 152. 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(-)
  153. 153. 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(-)
  154. 154. merging-demo master b115e79 00b26cb bc3583d 0c1f192 07e83b3 HEAD
  155. 155. Merging master merging-demo aff102e b115e79 00b26cb bc3583d 0c1f192 07e83b3 HEAD
  156. 156. Rebasing $ git rebase merging-demo First, rewinding head to replay your work on top of it... Applying: Remove 8.2 Applying: Remove 9
  157. 157. merging-demo master b115e79 00b26cb bc3583d 0c1f192 07e83b3 HEAD
  158. 158. merging-demo master b115e79 00b26cb HEAD bc3583d Remove 9 0c1f192 Remove 8.2 07e83b3
  159. 159. master 73dd819 Remove 9 67b81ce Remove 8.2 merging-demo b115e79 00b26cb 07e83b3 HEAD
  160. 160. master 73dd819 67b81ce merging-demo Remove 9 Remove 8.2 b115e79 00b26cb 07e83b3 HEAD
  161. 161. Later na lang yung merge vs rebase
  162. 162. Malapit na tayo mag-Github, but first...
  163. 163. Remote Repositories
  164. 164. Clone into another folder $ cd .. $ git clone devcon-git101 git101 Cloning into 'git101'... done.
  165. 165. Check the clone repo $ cd git101 $ gitk
  166. 166. HEAD HEAD master master merging-demo /devcon-git101 merging-demo /git101
  167. 167. remotes/origin/ master HEAD master master remotes/origin/ merging-demo merging-demo /devcon-git101 merging-demo /git101 HEAD
  168. 168. Show remote repos $ git remote origin
  169. 169. "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)
  170. 170. remotes/origin/ master HEAD master /devcon-git101 master /git101 HEAD
  171. 171. Synchronizing with Remote Repos
  172. 172. 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(+)
  173. 173. remotes/origin/ master HEAD master /devcon-git101 master /git101 HEAD
  174. 174. HEAD remotes/origin/ master master master /devcon-git101 /git101 HEAD
  175. 175. Fetching demo Go back to git101 and fetch the changes: $ cd ../git101 $ git fetch remote: 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
  176. 176. HEAD remotes/origin/ master master master /devcon-git101 /git101 HEAD
  177. 177. remotes/origin/ master HEAD master master /devcon-git101 /git101 HEAD
  178. 178. Merge the fetched branch $ git merge origin/master Updating 73dd819..cf5f902 Fast-forward names.txt | 1 + 1 file changed, 1 insertion(+)
  179. 179. remotes/origin/ master HEAD master master /devcon-git101 /git101 HEAD
  180. 180. A fast-forward occurs when you merge a branch which has HEAD as an ancestor. In this case, only the references are affected. remotes/origin/ master HEAD master master /devcon-git101 /git101 HEAD
  181. 181. 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.
  182. 182. Now that we understand the basic idea behind remote repos, let's proceed to Github... Sign-up at https://github.com
  183. 183. There are multiple ways to authenticate users in Git. We'll discuss the most secure one: via SSH keys.
  184. 184. Cryptography pasakalye...
  185. 185. Authentication via Password Client Server
  186. 186. Authentication via Password username + password Client sends credentials Server verifies password DB
  187. 187. Authentication via Password username + password Client sends credentials can be intercepted e.g. FTP Server verifies password DB
  188. 188. Authentication via SSH Key (oversimplified) Client has 2 "keys" private key public key Server
  189. 189. Authentication via SSH Key (oversimplified) Client has 2 "keys" private key public key Server has a list of authorized keys
  190. 190. Authentication via SSH Key (oversimplified) First, the public key must be sent to the server securely beforehand. Client has 2 "keys" private key public key Server has a list of authorized keys
  191. 191. Authentication via SSH Key (oversimplified) Using the private key, client can create a package that can only be unlocked by the corresponding public key and only that public key. Client private key public key Server has a list of authorized keys
  192. 192. Authentication via SSH Key (oversimplified) Using the private key, client can create a package that can only be unlocked by the corresponding public key and only that public key. Client private key public key Server has a list of authorized keys
  193. 193. Authentication via SSH Key (oversimplified) Using the private key, client can create a package that can only be unlocked by the corresponding public key and only that public key. Client private key public key Server has a list of authorized keys
  194. 194. Authentication via SSH Key (oversimplified) Using the private key, client can create a package that can only be unlocked by the corresponding public key and only that public key. Client private key public key doesn't matter if intercepted since they still need to crack it. Server has a list of authorized keys
  195. 195. 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.
  196. 196. 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.
  197. 197. Fortunately, there is a workaround that will only require you to enter it once per session. http://stackoverflow.com/a/9011152
  198. 198. Create a repo in Github for devcon-git101 https://github.com/new
  199. 199. Pushing devcon-git101 Go back to devcon-git101 and push it to your new repo (use SSH url) $ git remote add origin git@github.com:user/devcon-git101.git $ git push -u origin master Warning: 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 git@github.com:user/devcon-git101.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
  200. 200. git push Note 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
  201. 201. Clone into another folder $ cd .. $ git clone git@github.com:user/devcon-git101.git github-git101 Cloning 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.
  202. 202. play time With the cloned folder, you can now play around with certain collaboration scenarios. For example: 1. Make some changes in /devcon-git101 2. 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"
  203. 203. Want to let someone else push to your repo? Go to the repo Settings → Collaborators and add your friends.
  204. 204. 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.
  205. 205. 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
  206. 206. Best Practices
  207. 207. 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.
  208. 208. 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.
  209. 209. 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.
  210. 210. 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.
  211. 211. 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.
  212. 212. Helpful Stuff that we will still not explain in detail...
  213. 213. Graphical Git Tools
  214. 214. Client - Server VCS vs Distributed VCS
  215. 215. Push-based vs Pull-based
  216. 216. Backups
  217. 217. GitHub as a Project Management Tool
  218. 218. GitHub as a Project Management Tool for Open Source Projects
  219. 219. GitHub as a Portfolio
  220. 220. Branches + Workflow
  221. 221. Tagging + Deployment
  222. 222. Free Private Repos Since 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
  223. 223. 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
  224. 224. 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
  225. 225. Commands that I use everyday git pull --rebase git add git commit -am "blah blah" gitk / git log / git status / git diff git push
  226. 226. 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
  227. 227. Thank You For Listening!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×