lets git together

58
$> git init

Upload: rakesh-jha

Post on 24-Jan-2017

37 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Lets Git Together

$> git init

Page 2: Lets Git Together

Short HistoryLinus uses BitKeeper to manage Linux codeRan into BitKeeper licensing issueLiked functionalityLooked at CVS as how not to do thingsApril 5, 2005 - Linus sends out email showing first versionJune 15, 2005 - Git used for Linux version control

Page 3: Lets Git Together

Centralized VC vs. Distributed VC

Central ServerRemote Server

Page 4: Lets Git Together

SVN vs. Git

SVN ServerGit Server

Page 5: Lets Git Together

SVN

CentralizedCheckoutsBranchingConflict ResolutionNo Offline supportSimple and easy to learn

Page 6: Lets Git Together

GIT

DeCentralizedFast, Reliable, ConsistentBranching / CheckoutsConflict ResolutionsOffline supportWide range of deployment hooks

Page 7: Lets Git Together

SVN Commandsco - checkoutlistaddcommitupdate

Git Commandsinitclonestatusaddcommitpushpull / fetch

Page 8: Lets Git Together

Git Work-flowRemote Server

Workingcopy

Page 9: Lets Git Together

Git Work-flowRemote Server

Workingcopy

StageArea

> git add file-name

Page 10: Lets Git Together

Git Work-flowRemote Server

LocalRepo

Workingcopy

StageArea

> git commit -m ‘message’

Page 11: Lets Git Together

Git Work-flowRemote Server

LocalRepo

Workingcopy

StageArea

> git push origin master

Page 12: Lets Git Together

Cloning a repository

> git clone url

> git clone [email protected]/username/myproject.git

> git clone https://github.com/username/

myproject.git

> cd myproject

Page 13: Lets Git Together

Git configGlobal configuration> git config --global user.name your.name> git config --global user.email your.emailProject configuration

> cd myproject> git config user.name your.name> git config user.email your.email

Page 14: Lets Git Together

Creating a new Repo

Initialized empty Git repository in ~/myproject/.git

[master (root-commit) 7106a52] my first commit 1 file changed, 1 insertion(+) create mode 100644 README.txt

> mkdir myproject> cd myproject> git init

> touch README.txt> git add .> git commit -m 'my first commit'

Page 15: Lets Git Together

Adding a remote server> git remote add origin [email protected]/username/myproject.git> git remote -vorigin [email protected]/username/myproject.git (fetch)origin [email protected]/username/myproject.git (push)

Page 16: Lets Git Together

Adding a remote server> git remote add origin [email protected]/username/myproject.git> git remote -vorigin [email protected]/username/myproject.git (fetch)origin [email protected]/username/myproject.git (push)

> git remote add production [email protected]/live/myproject.git> git remote -vorigin [email protected]/username/myproject.git (fetch)origin [email protected]/username/myproject.git (push)production [email protected]/live/project.git (fetch)production [email protected]/live/project.git (push)

Page 17: Lets Git Together

Adding files

Will stage your file to be committedConventionally `git add .` should be avoided

Will stage all your deleted files to be deleted from repository

> git add -u

> git add [file-name | dot(.)]

Page 18: Lets Git Together

Commit files

Will commit your file to your local repository

With inline message

Equivalent of [git add . + git commit -m]

> git commit

> git commit -m ‘message’

> git commit -am ‘message’

Page 19: Lets Git Together

Pull

Will pull latest commits from the remote repository and try to auto merge them

> git pull remote branch

> git pull origin master

Page 20: Lets Git Together

Push

Will push your commits to the remote repository

Another dangerous command.Overrides any previous commit/changes

> git push remote branch

> git push origin master

> git push -f origin master

Page 21: Lets Git Together

Branching

Branches in Git basically is a collection of commits

By default ‘master’ branch is available in all repositories

> git branch

> git branch new-branch> git branch -D your-branch

lists all branchescreates new branch

deletes a branch

Page 22: Lets Git Together

master

A

> git commit –m ‘my first commit’

Branching

Page 23: Lets Git Together

master

> git commit (x2)

A B C

Branching

Page 24: Lets Git Together

bug123

master

> git checkout –b bug123

A B C

Branching

Page 25: Lets Git Together

master

> git commit (x2)

A B CD E

bug123

Branching

Page 26: Lets Git Together

master

> git checkout master

A B CD E

bug123

Branching

Page 27: Lets Git Together

bug123

master

> git merge bug123

A B C D E

Branching

Page 28: Lets Git Together

master

> git branch -d bug123

A B C D Ebug12

3

Branching

Page 29: Lets Git Together

Advance branching and merging

Page 30: Lets Git Together

Branches Illustrated

masterA B C D E

F Gbug45

6

Page 31: Lets Git Together

masterA B C D E

F Gbug45

6

> git checkout master

Branches Illustrated

Page 32: Lets Git Together

masterA B C D E

F G

> git merge bug456

H

bug456

Branches Illustrated

Page 33: Lets Git Together

masterA B C D E

F Gbug45

6

Branches Illustrated

Page 34: Lets Git Together

masterA B C D E

> git rebase master

F Gbug45

6

Branches Illustrated

Page 35: Lets Git Together

masterA B C D E

> git checkout master> git merge bug456

F Gbug45

6

Branches Illustrated

Page 36: Lets Git Together

More git commands

Shows difference between working copy and last revision

> git diff [file-name]

Page 37: Lets Git Together

More git commands

Shows difference between working copy and last revision

Shows a complete history of commits with dates and author-name

> git diff [file-name]

> git log

Page 38: Lets Git Together

More git commands

Shows who/when made changes to a file line-by-line

> git blame [file-name]

Page 39: Lets Git Together

More git commands

Shows who/when made changes to a file line-by-line

Renames a branch

> git blame [file-name]

> git branch -m <old-name> <new-name>

Page 40: Lets Git Together

More git commands

Remote branch trackingUpdates your local repository with remote

branches

> git fetch

Page 41: Lets Git Together

More git commands

Stashing takes the dirty state of your working directory - that is, your modified tracked files and staged changes - and saves it on a stack of unfinished changes that you can reapply at any time.

> git stash

Page 42: Lets Git Together

> git status# On branch master# Changes to be committed:# (use "git reset HEAD <file>..." to unstage)## modified: index.html## Changes not staged for commit:# (use "git add <file>..." to update what will be committed)## modified: lib/simplegit.rb

Page 43: Lets Git Together

> git stashSaved working directory and index state \ "WIP on master: 049d078 added the index file"HEAD is now at 049d078 added the index file(To restore them type "git stash apply")

Page 44: Lets Git Together

> git status# On branch masternothing to commit, working directory clean

Page 45: Lets Git Together

> git merge issue53Auto-merging index.htmlCONFLICT (content): Merge conflict in index.htmlAutomatic merge failed; fix conflicts and then commit the result.

Page 46: Lets Git Together

> git merge issue53Auto-merging index.htmlCONFLICT (content): Merge conflict in index.htmlAutomatic merge failed; fix conflicts and then commit the result.

Merge Conflict

Page 47: Lets Git Together

> git merge issue53Auto-merging index.htmlCONFLICT (content): Merge conflict in index.htmlAutomatic merge failed; fix conflicts and then commit the result.

Merge Conflict

Page 48: Lets Git Together

How to solve it?

Page 49: Lets Git Together

<<<<<<< HEAD:index.html<div id="footer">contact : [email protected]</div>=======<div id="footer"> please contact us at [email protected]</div>>>>>>>> issue53:index.html

Page 50: Lets Git Together

<div id="footer">please contact us at [email protected]</div>

Page 51: Lets Git Together

<div id="footer">please contact us at [email protected]</div>

Page 52: Lets Git Together

Installation

Windowshttp://git-scm.com/download/win

Linux$ sudo apt-get install git (Ubuntu)$ yum install git(CentOs)

Machttp://git-scm.com/download/mac

Page 53: Lets Git Together

Best Practices

Do not work on Master branchSynchronize dailyFollow feature-wise branchingAvoid force pushDo not work on servers

e.g FTP

Page 54: Lets Git Together

Tools

● Following are few very necessary tool for working with git

> sudo apt-get install gitg> sudo apt-get install git-gui> sudo apt-get install meld

Page 55: Lets Git Together

GitG (gitg)

Page 56: Lets Git Together

Git-GUI (git gui)

Page 57: Lets Git Together

Meld (git mergetool)

Page 58: Lets Git Together

Thank You

- Waqar Baig

Special credits to Rails Team