Checkout an existing
repository
$ git clone [email protected]:oSoc13/Media.git
Cloning into 'Media'...
Resolving deltas: 100% (2/2), done.
Slide 9
Slide 9 text
git add
Add changes to the index
$ git add README
$ git add subfolder/*
Add all files (including deleted files)
$ git add -A
Slide 10
Slide 10 text
git commit
Create a new version of repository with added changes
$ git commit -m “Adding readme”
[master] created d9e1758: “Adding readme”
1 files changed, 1 insertions(+), 0 deletions(-)
git pull
Pull updates from a remote repository
$ git pull [remote] [branch]
$ git pull origin master
remote: Total 3 (delta 0), reused 0 (delta 0)
Updating d9e1758..c3e12cc
Slide 13
Slide 13 text
Conflicts
Slide 14
Slide 14 text
Conflicts
A file was modified since the last pull
$ git push origin master
! [rejected] master -> master (non-fast-
forward)
Slide 15
Slide 15 text
Inspecting the conflict
Update your repository
$ git pull
View conflict info
$ git status
Unmerged paths:
both modified: README
Slide 16
Slide 16 text
Resolving the conflict
Open the conflicted file in your favorite editor
$ nano README
<<<<<<< HEAD
$var = ‘foo’;
=======
$var = ‘bar’;
>>>>>>> a0b0bf3
]
]
local repository
remote repository
Typical branches
• Master
The latest stable version of the project
• Staging/Develop
The branch where the a beta version is tested before it is
merged into the master branch
• Feature X
A branch where a specific feature is being developed
Slide 21
Slide 21 text
Creating a branch
From the base branch
$ git branch feature-x
Switching to the new branch
$ git checkout feature-x
Slide 22
Slide 22 text
Merging a branch
Switch to the base branch you want to merge in
$ git checkout master
Merge with the branch
$ git merge staging
Slide 23
Slide 23 text
Updating a branch
Update a feature branch with master branch bug fixes
$ git checkout feature-x
$ git merge master
Slide 24
Slide 24 text
Tips and tricks
Slide 25
Slide 25 text
.gitignore
A list of files that should be ignored
# OS generated files
.DS_Store
.Trashes
Thumbs.db
# Config
Config.php
Slide 26
Slide 26 text
When all hope is lost
Revert all changes to the last pulled version
$ git reset --hard HEAD
Slide 27
Slide 27 text
SSH keys
WARNING! Only when you do not have an existing key pair
$ ssh-keygen -t rsa -C "[email protected]"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/
you/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type
a passphrase]
Slide 28
Slide 28 text
SSH keys (2)
Add your public SSH key to your github account (account
settings)
$ cat ~/.ssh/id_rsa.pub
Test your settings
$ ssh -T [email protected]
Hi username! You've successfully authenticated,
but GitHub does not provide shell access.