28
Git - Basics

Version Control History and Git Basics

Embed Size (px)

Citation preview

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

Centralised VCS vs Distributed VCS

● 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

● 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

● 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

● 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

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

Repository

● Centralized VCS○ List of file based changes

● Distributed VCS○ Set of snapshots of a miniature filesystem

Data Storage in a repository

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

What is a Diff?

● 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

● 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

Linus Torvalds Junio Hamano

● Bazaar● Mercurial● Monotone

Other softwares like Git

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

Make your first git repository

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

Confusions of a Subversion user

● git add .● git commit● git push

Your first commit

● 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

● 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.)

● 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.)

● 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.)

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

● Search○ git grep "foo()"

Git common commands (Contd.)

● Creating a new repository

● Cloning a remote repository

Git for subversion users

● Inspecting history

● Committing local changes○ Inspect your local changes

Git for subversion users (Contd.)

● Committing local changes○ add/remove changed files

○ commit your changes

Git for subversion users (Contd.)

● Sharing & collaborating

Git for subversion users (Contd.)

Thank You&

Next Presentation will be on unit testing