28
workshop Introduction to git (version control system) By Samundra Shrestha 1

Brown bag sessions git workshop

Embed Size (px)

Citation preview

Page 1: Brown bag sessions git workshop

1

workshopIntroduction to git (version control system)

By Samundra Shrestha

Page 2: Brown bag sessions git workshop

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

Page 3: Brown bag sessions git workshop

3

DISTRIBUTED VERSION CONTROL SYSTEMS

Page 4: Brown bag sessions git workshop

4

HISTORY OF GIT

Linux kernel project (during 1991-2002) DVCS Bitkeeper unavailable Developed in 2005 by Linus Torvalds

Page 5: Brown bag sessions git workshop

5

GIT IS OPTIMIZED FOR: Distributed development Large file counts Complex merges Making trial branches Being very fast Being robust

Page 6: Brown bag sessions git workshop

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

Page 7: Brown bag sessions git workshop

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

Page 8: Brown bag sessions git workshop

8

COMPANIES USING GIT

Page 9: Brown bag sessions git workshop

9

How Git INTERNALLY works ?

Answer: SHA1 HASH

Page 10: Brown bag sessions git workshop

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.

Page 11: Brown bag sessions git workshop

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)

Page 12: Brown bag sessions git workshop

12

USE GIT FROM GIT BASH ONLY

Run > Git BashSwitching drives > cd {drive_letter} eg. cd f:

After Installations:

Page 13: Brown bag sessions git workshop

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

Page 14: Brown bag sessions git workshop

14

GIT GLOBAL VARIABLES

> git config --list

Page 15: Brown bag sessions git workshop

15

WHERE TO GET HELP ?

git {command_name} --help> git add --help

?

Page 16: Brown bag sessions git workshop

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"

Page 17: Brown bag sessions git workshop

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

Page 18: Brown bag sessions git workshop

18

PUSH FILE TO REMOTE

git status

git add file1.txt

Page 19: Brown bag sessions git workshop

19

PUSH FILE TO REMOTEgit remote add origin [email protected]:samundra/git-presentation.git

Page 20: Brown bag sessions git workshop

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>…]]

Page 21: Brown bag sessions git workshop

21

BASIC GIT WORKFLOWS

Master

Develop Feature Request

commits/changesgit branches

push/pull

Page 22: Brown bag sessions git workshop

22

BRANCHING ON GIT

List all branchesgit branch

Master

Develop

•Create and switch• git checkout –b {branch_name}

* is the current active branch

Page 23: Brown bag sessions git workshop

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

Page 24: Brown bag sessions git workshop

24

VIDEO TUTORIAL ON GIT WORKFLOW

Video Tutorial is available on

https://drive.google.com/file/d/0B1z71cfDxHUmTXdwNU02VGl6Zm8/edit?usp=sharing

Page 25: Brown bag sessions git workshop

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/)

Page 26: Brown bag sessions git workshop

26

Thank You All Questions

?

Page 27: Brown bag sessions git workshop

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

Page 28: Brown bag sessions git workshop

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