Top Banner
Git - Basics
28
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Version Control History and Git Basics

Git - Basics

Page 2: Version Control History and Git Basics

● Management of changes to collection of Information● Identified by revision number● Revisions can be compared restored and merged● Coordinating Teams

Version Control Software

Page 3: Version Control History and Git Basics

Centralised VCS vs Distributed VCS

Page 4: Version Control History and Git Basics

● One true source code● Commit and Checkout from a central location● No need to keep many copies of single file in hard disk● Eg:- SVN, OpenCVS and Perforce● Difference in workflow and performance● Typical CVCS Workflow

○ Pull down any changes other people have made from the central server

○ Make your changes, and make sure they work properly○ Commit your changes to the central server, so other programmers

can see them

Centralised VCSs

Page 5: Version Control History and Git Basics

● Every repository is good as any other● Do not necessarily rely on a central server● Developer “clones” a copy of a repository and has the full history of the

project on their own hard drive● “Pulling” and “Pushing”● Act of cloning

Distributed VCSs

Page 6: Version Control History and Git Basics

● Actions other than pushing and pulling to repositories are extremely fast● Committing new changesets can be done locally● Work and commit changes from anywhere without Internet, push them

all to git server at once● Share with one or two people to get feedback and then share with all

Advantages of DVCS

Page 7: Version Control History and Git Basics

● Space needed to store all version of large binary files can accumulate quickly

● Long history projects can take an impractical amount of time and disk space

Disadvantages of DVCS

Page 8: Version Control History and Git Basics

● Location in which data is stored and managed○ Central location○ Distributed location

Repository

Page 9: Version Control History and Git Basics

● Centralized VCS○ List of file based changes

● Distributed VCS○ Set of snapshots of a miniature filesystem

Data Storage in a repository

Page 10: Version Control History and Git Basics

● Difference between same file in different versions of a VCS● Eg :-

What is a Diff?

Page 11: Version Control History and Git Basics

● Distributed revision control system● Designed and developed by Linus Torvalds● A Git working repository is a fully-fledged repository● Distributed under GNU General Public License version 2

Git

Page 12: Version Control History and Git Basics

● Development began in April 2005● BitKeeper - A proprietary source control management system● Necessity of an distributed open source SCM● Other design Criterias

○ Take Concurrent Versions System (CVS) as an example of what not to do; if in doubt, make the exact opposite decision

○ Support a distributed, BitKeeper-like workflow○ Very strong safeguards against corruption, either accidental or

malicious● “The unpleasant person”

Evolution of Git

Page 13: Version Control History and Git Basics

Linus Torvalds Junio Hamano

Page 14: Version Control History and Git Basics

● Bazaar● Mercurial● Monotone

Other softwares like Git

Page 15: Version Control History and Git Basics

● Command-line method○ git init○ git init <reponame>○ git --bare init

Make your first git repository

Page 16: Version Control History and Git Basics

● SVN Checkout and Git Clone● SVN Update and Git Pull● SVN Commit and Git commit & push

Confusions of a Subversion user

Page 17: Version Control History and Git Basics

● git add .● git commit● git push

Your first commit

Page 18: Version Control History and Git Basics

● Tell Git who you are○ git config --global user.name "Sam Smith"○ git config --global user.email [email protected]

● Create a new local repository○ git init

● Checkout a repository○ git clone /path/to/repository○ git clone username@host:/path/to/repository

● Add files○ git add <filename>○ git add .

Git common commands

Page 19: Version Control History and Git Basics

● Commit○ git commit -m “commit message”○ git commit -a

● Push○ git push origin master

● Status○ git status

● Connect to a remote repository○ git remote add origin <server>○ git remote -v

Git common commands (Contd.)

Page 20: Version Control History and Git Basics

● Branches○ git checkout -b <branchname>○ git checkout <branchname>○ git branch○ git branch -d <branchname>○ git push origin <branchname>○ git push --all origin○ git push origin :<branchname>

Git common commands (Contd.)

Page 21: Version Control History and Git Basics

● Update from the remote repository○ git pull○ git merge <branchname>○ git diff○ git diff --base <filename>○ git diff <sourcebranch> <targetbranch>○ git add <filename>

● Tags○ git tag 1.0.0 <commitID>○ git log○ git push --tags origin

Git common commands (Contd.)

Page 22: Version Control History and Git Basics

● Undo local changes○ git checkout -- <filename>○ git fetch origin○ git reset --hard origin/master

● Search○ git grep "foo()"

Git common commands (Contd.)

Page 23: Version Control History and Git Basics

● Creating a new repository

● Cloning a remote repository

Git for subversion users

Page 24: Version Control History and Git Basics

● Inspecting history

● Committing local changes○ Inspect your local changes

Git for subversion users (Contd.)

Page 25: Version Control History and Git Basics

● Committing local changes○ add/remove changed files

○ commit your changes

Git for subversion users (Contd.)

Page 26: Version Control History and Git Basics

● Sharing & collaborating

Git for subversion users (Contd.)

Page 27: Version Control History and Git Basics
Page 28: Version Control History and Git Basics

Thank You&

Next Presentation will be on unit testing