Git101
-
Upload
jens-segers -
Category
Technology
-
view
314 -
download
0
description
Transcript of Git101
![Page 1: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/1.jpg)
Git 101@jenssegers
![Page 2: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/2.jpg)
In a world without Git
![Page 3: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/3.jpg)
Distributed version control
• Speed
• Simple
• Non-linear development
• Fully distributed
• Large projects
![Page 4: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/4.jpg)
Snapshots, no ∆
![Page 5: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/5.jpg)
Distributed
Pieter
Hannes
Jens
Miet
![Page 6: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/6.jpg)
Distributed and managed
Pieter
Hannes
Jens
Miet
![Page 7: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/7.jpg)
Github
Pieter
Hannes
Jens
![Page 8: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/8.jpg)
What is Github?
• Repository hosting service
• Visualization of changes
• Issue tracker
![Page 9: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/9.jpg)
Installing Git
• WindowsGit Bash with MinGW
• OSX and LinuxTerminal
git-scm.com
![Page 10: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/10.jpg)
Git configuration
$ git config --global user.name “Your Name”
$ git config --global user.email “[email protected]”
![Page 12: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/12.jpg)
Creating a local repository
$ mkdir Hello
$ cd Hello
$ git init
Initialized empty Git repository in Hello/.git/
$ git remote add origin [email protected]:user/Hello.git
![Page 13: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/13.jpg)
Git Basics
![Page 14: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/14.jpg)
git add
Track files for the next snapshot
$ git add README
$ git add subfolder/
Add all files (including deleted files)
$ git add -A
![Page 15: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/15.jpg)
git rm
Opposite of add, untracks file
$ git rm README
Recursive
$ git rm -r subfolder/
![Page 16: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/16.jpg)
git commit
Create a snapshot of all the added files
$ git commit -m “Adding readme”
[master] created d9e1758: “Adding readme”1 files changed, 1 insertions(+), 0 deletions(-)
Always add an appropriate commit message!
![Page 17: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/17.jpg)
git commit (2)
Automatically detect changed and deleted files
$ git commit -am “Adding readme”
Update a previous commit
$ git commit -am “GUI refactoring”
$ git add new_file
$ git commit --amend
![Page 18: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/18.jpg)
git push
Push commit snapshots to a remote repository
$ git push [remote] [branch]
$ git push origin master
Writing objects: 100% (3/3), 225 bytes, done.Total 3 (delta 0), reused 0 (delta 0)
![Page 19: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/19.jpg)
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
![Page 20: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/20.jpg)
git clone
Work on an existing repository
$ git clone [origin]
$ git clone https://github.com/user/repository.git
Cloning into ...Unpacking objects: 100%, done.
![Page 21: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/21.jpg)
Conflicts
![Page 22: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/22.jpg)
Conflicts
A file was modified since the last pull
$ git push origin master
! [rejected] master -> master (non-fast-forward)
![Page 23: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/23.jpg)
Inspecting the conflict
Update your repository
$ git pull
View conflict info
$ git status
Unmerged paths:both modified: README
![Page 24: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/24.jpg)
Resolving the conflict
Open the conflicted file in your favorite editor
$ nano README
<<<<<<< HEADYes, this is Dog?=======Who is Dog?>>>>>>> a0b0bf3
]]
local repository
remote repository
![Page 25: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/25.jpg)
Push merged file
$ git add README
$ git commit -m “Merging”
$ git push origin master
![Page 26: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/26.jpg)
Branching
![Page 27: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/27.jpg)
Branches
![Page 28: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/28.jpg)
Typical branches
• MasterThe latest stable version of the project
• StagingThe branch where the a beta version is tested before it is merged into the master branch
• Feature XA branch where a specific feature is being developed
![Page 29: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/29.jpg)
Creating a branch
From the base branch
$ git branch feature-x
Switching to the new branch
$ git checkout feature-x
![Page 30: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/30.jpg)
Merging a branch
Switch to the base branch you want to merge in
$ git checkout master
Merge with the branch
$ git merge staging
![Page 31: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/31.jpg)
Updating a branch
Update a feature branch with master branch bug fixes
$ git checkout feature-x
$ git merge master
![Page 32: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/32.jpg)
Removing a branch
$ git branch -D feature-useless
![Page 33: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/33.jpg)
Tips and tricks
![Page 34: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/34.jpg)
.gitignore
A list of files that should be ignored
# OS generated files.DS_Store.TrashesThumbs.db
# ConfigConfig.php
![Page 35: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/35.jpg)
When all hope is lost
Revert all changes to the last pulled version
$ git reset --hard HEAD
![Page 36: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/36.jpg)
Credential cache
Add cache to credentials to prevent typing username and password over and over again
$ git config --global credential.helper cache
Default cache is 15 minutes, to change cache use
$ git config credential.helper 'cache --timeout=3600'
![Page 37: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/37.jpg)
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]
![Page 38: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/38.jpg)
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.
![Page 39: Git101](https://reader033.fdocuments.in/reader033/viewer/2022052823/5557ac45d8b42a696c8b4a95/html5/thumbnails/39.jpg)
Good luck
thanksTim De Pauw, Pieter Colpaert, Hannes Van De Vreken