Upload
bishant-shrestha
View
235
Download
0
Embed Size (px)
Citation preview
1
workshopIntroduction to git (version control system)
By Samundra Shrestha
2
WHAT IS GIT ?
Distributed Version Control Systems Changes track over the entire repository (tree of files)
Similar VCS
• Subversion• Mercurial• CVS• Perforce
• Git has integrity• SHA-1 hash (40 –character string composed of hexadecimal characters, 0-9 & a-f)• E.g. 8abc7564536d0756ec30a37c49e9a894ad822d52
3
DISTRIBUTED VERSION CONTROL SYSTEMS
4
HISTORY OF GIT
Linux kernel project (during 1991-2002) DVCS Bitkeeper unavailable Developed in 2005 by Linus Torvalds
5
GIT IS OPTIMIZED FOR: Distributed development Large file counts Complex merges Making trial branches Being very fast Being robust
6
BENEFITS OF GIT
Work completely offline Commit any time you feel like, even when you are not on network.
Branching is piece of cake Only one .git directory per repository
SVN has .svn folder in each folder it contains, hard to maintain Easy to manage ignore files Easy peer review
7
POPULAR FREE HOSTINGS FOR GIT
Github.com (only public repos, commercial private repos)http://www.github.com
Bitbucket.org (private and public repos)http://www.bitbucket.org
8
COMPANIES USING GIT
9
How Git INTERNALLY works ?
Answer: SHA1 HASH
10
GIT HASHES CONTINUED …
Git Tracks Everything by hashes (40 hex characters) Globally Unique Identifier
8abc756 4536d0756ec30a37c49e9a894ad822d52
First 7 characters are shorthand for the
hashes.
11
SETUP REQUIRED
•Access to git server• sign up account in http://www.bitbucket.org (Cloud based server)
•Git client - git bash shell• Install git bash shell in machine (only for windows)• http://git-scm.com/download/win
• sudo apt-get install git (Ubuntu, Debian based systems)
12
USE GIT FROM GIT BASH ONLY
Run > Git BashSwitching drives > cd {drive_letter} eg. cd f:
After Installations:
13
IDENTIFY YOURSELF TO GIT::CONFIG
> git config --global user.name="Samundra Shrestha"> git config --global user.email="[email protected]"
gi t config - -g lobal {opt ion="value"}
HEADS, REFS, OBJECTS, HOOKS, CONFIGS
14
GIT GLOBAL VARIABLES
> git config --list
15
WHERE TO GET HELP ?
git {command_name} --help> git add --help
?
16
INITIALIZE GIT REPOSITORY
Create new directory> mkdir git-presentation
Change path to newly created directory> cd git-presentation
Tell system that we want this directory to be our git repository
> git initCreate file1.txt
> touch "file1.txt"
17
INITIALIZE GIT REPOSITORY CONTD…
> git add .> git status> git commit -am "initial commit"> git remote add origin [email protected]:samundra/git-presentation.git> git push -u origin master> git log
18
PUSH FILE TO REMOTE
git status
git add file1.txt
19
PUSH FILE TO REMOTEgit remote add origin [email protected]:samundra/git-presentation.git
20
PULL/PUSH CHANGES TO REMOTE HOSTINGS
List all remote urlsgit remote –v
Push changesgit push –u origin master (-u tracks remote changes
used only first time.)git push
Pull changesgit pull [options] [<repository> [<refspec>…]]
21
BASIC GIT WORKFLOWS
Master
Develop Feature Request
commits/changesgit branches
push/pull
22
BRANCHING ON GIT
List all branchesgit branch
Master
Develop
•Create and switch• git checkout –b {branch_name}
* is the current active branch
23
MERGE BRANCHES
Master
Develop
git merge develop --no-ff
• Omitting --no-ff will create fast-forward commit and we'll lose track that there was develop branch which got merged into master branch.
• So, we'll have a straight line after merge and we will not see branch split of develop.
• So use --no-ff to merge branches for history purpose. Recommended
branch commitregular commit
24
VIDEO TUTORIAL ON GIT WORKFLOW
Video Tutorial is available on
https://drive.google.com/file/d/0B1z71cfDxHUmTXdwNU02VGl6Zm8/edit?usp=sharing
25
POPULAR GIT CLIENTS
gitk (comes bundles with git-preview installed by default on most) Smartgit (http://www.syntevo.com/smartgithg/) GitEye (http://www.giteyeapp.com/) SourceTree (http://www.sourcetreeapp.com/)
26
Thank You All Questions
?
27
POPULAR GIT COMMANDS
• git init• git clone• git status• git log• git stash• git add
• git commit• git push• git pull• git checkout• git stash• git add
• git diff• git branch• git merge• git fetch• git reset• git format-patch
28
REFERENCES Git Cheatsheet; http://www.ndpsoftware.com/git-cheatsheet.html (visually pretty) Atlassian, Make the switch to Git; https://www.atlassian.com/git?
_mid=83863a53e6e38075309c21d2539cbfb9&gclid=CODX0bfpur4CFZYGvAod8KUAHQ Getting Started Git Basics; http://git-scm.com/book/en/Getting-Started-Git-Basics Github training cheat sheet: https://training.github.com/kit/downloads/github-git-cheat-sheet.pdf From Git-Tower: http://www.git-tower.com/blog/git-cheat-sheet/ Atlassian Git Tutorials; https://www.atlassian.com/git/tutorial/ Lines of Code in Linux Kernel; http://www.quora.com/Linux-Kernel/How-many-lines-of-code-are-in-the-
Linux-kernel Git slideshare; http://www.slideshare.net/RandalSchwartz/introduction-to-git-11451326 Linus Torvalds & Git Video; https://www.youtube.com/watch?v=idLyobOhtO4 Git GUIs; http://git-scm.com/downloads/guis Git workflows; https://www.atlassian.com/git/workflows 10Clouds on Talk; https://www.youtube.com/watch?v=bzbuyIe3kUU