lets git together

Post on 24-Jan-2017

37 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

$> git init

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

Centralized VC vs. Distributed VC

Central ServerRemote Server

SVN vs. Git

SVN ServerGit Server

SVN

CentralizedCheckoutsBranchingConflict ResolutionNo Offline supportSimple and easy to learn

GIT

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

SVN Commandsco - checkoutlistaddcommitupdate

Git Commandsinitclonestatusaddcommitpushpull / fetch

Git Work-flowRemote Server

Workingcopy

Git Work-flowRemote Server

Workingcopy

StageArea

> git add file-name

Git Work-flowRemote Server

LocalRepo

Workingcopy

StageArea

> git commit -m ‘message’

Git Work-flowRemote Server

LocalRepo

Workingcopy

StageArea

> git push origin master

Cloning a repository

> git clone url

> git clone git@github.com/username/myproject.git

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

myproject.git

> cd myproject

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

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'

Adding a remote server> git remote add origin git@github.com/username/myproject.git> git remote -vorigin git@github.com/username/myproject.git (fetch)origin git@github.com/username/myproject.git (push)

Adding a remote server> git remote add origin git@github.com/username/myproject.git> git remote -vorigin git@github.com/username/myproject.git (fetch)origin git@github.com/username/myproject.git (push)

> git remote add production git@github.com/live/myproject.git> git remote -vorigin git@github.com/username/myproject.git (fetch)origin git@github.com/username/myproject.git (push)production git@github.com/live/project.git (fetch)production git@github.com/live/project.git (push)

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(.)]

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’

Pull

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

> git pull remote branch

> git pull origin master

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

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

master

A

> git commit –m ‘my first commit’

Branching

master

> git commit (x2)

A B C

Branching

bug123

master

> git checkout –b bug123

A B C

Branching

master

> git commit (x2)

A B CD E

bug123

Branching

master

> git checkout master

A B CD E

bug123

Branching

bug123

master

> git merge bug123

A B C D E

Branching

master

> git branch -d bug123

A B C D Ebug12

3

Branching

Advance branching and merging

Branches Illustrated

masterA B C D E

F Gbug45

6

masterA B C D E

F Gbug45

6

> git checkout master

Branches Illustrated

masterA B C D E

F G

> git merge bug456

H

bug456

Branches Illustrated

masterA B C D E

F Gbug45

6

Branches Illustrated

masterA B C D E

> git rebase master

F Gbug45

6

Branches Illustrated

masterA B C D E

> git checkout master> git merge bug456

F Gbug45

6

Branches Illustrated

More git commands

Shows difference between working copy and last revision

> git diff [file-name]

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

More git commands

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

> git blame [file-name]

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>

More git commands

Remote branch trackingUpdates your local repository with remote

branches

> git fetch

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

> 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

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

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

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

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

Merge Conflict

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

Merge Conflict

How to solve it?

<<<<<<< HEAD:index.html<div id="footer">contact : email.support@github.com</div>=======<div id="footer"> please contact us at support@github.com</div>>>>>>>> issue53:index.html

<div id="footer">please contact us at email.support@github.com</div>

<div id="footer">please contact us at email.support@github.com</div>

Installation

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

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

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

Best Practices

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

e.g FTP

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

GitG (gitg)

Git-GUI (git gui)

Meld (git mergetool)

Thank You

- Waqar Baig

Special credits to Rails Team

top related