SlideShare a Scribd company logo
GIT
By Soumen Debgupta
Learning Objectives
• How git creates a mini-filesystem in your directory
• What commit, push, pull do
• The elements of the basic git workflow
• How git allows you to work across multiple computers
• How git allows you and a partner to work together
Git is a distributed version-control system
• You keep your files in a repository on your local machine.
• You synchronize your repository with a repository on a server.
• If you move from one machine to another, you can pick up the
changes by synchronizing with the server.
• If your partner uploads some changes to your files, you can pick those
up by synchronizing with the server.
Why Git?
• Over 70% of developers use Git!
• Developers can work together from anywhere in the world.
• Developers can see the full history of the project.
• Developers can revert to earlier versions of a project.
GIT Introduction
• Created by Linus Torvalds,
creator of Linux, in 2005
– Came out of Linux development community
– Designed to do version control on Linux kernel
• Goals of Git:
– Speed
– Support for non-linear development
(thousands of parallel branches)
– Fully distributed
– Able to handle large projects efficiently
Git is a Distributed Version-control System
• Terminology: In git-speak, a “version” is called a “commit.”
• Git keeps track of the history of your commits, so you can go back and
look at earlier versions, or just give up on the current version and go
back some earlier version.
Centralized VCS
In Subversion, CVS, Perforce, etc.
A central server repository (repo)
holds the "official copy" of the code
– the server maintains the sole
version history of the repo
• You make "checkouts" of it
to your local copy
– you make local modifications
– your changes are not versioned
• When you're done, you
"check in" back to the server
– your checkin increments the repo's version
GIT Snapshots
• Centralized VCS like Subversion
track version data on each
individual file.
• Git keeps "snapshots" of the
entire state of the project.
– Each checkin version of the
overall code has a copy of
each file in it.
– Some files change on a given
checkin, some do not.
– More redundancy, but faster.
Subversion
GIT
Local Git Areas
• In your local copy on git,
files can be:
– In your local repo
• (committed)
– Checked out and modified,
but not yet committed
• (working copy)
– Or, in-between, in
a "staging" area
• Staged files are ready
to be committed.
• A commit saves a snapshot of all staged state.
Committed
Files
Staged
Files
Unmodified/modifie
d Files
GIT Operations
Git Commit Checksums
• In Subversion each modification to the central repo increments
the version # of the overall repo.
– In Git, each user has their own copy of the repo, and commits
changes to their local copy of the repo before pushing to the
central server.
– So Git generates a unique SHA-1 hash (40 character string
of hex digits) for every commit.
– Refers to commits by this ID rather than a version number
– Often we only see the first 7 characters:
• 1677b2d Edited first line of readme
• 258efa7 Added line to readme
• 0e52da7 Initial commit
Initial Git configuration
• Set the name and email for Git to use when you commit:
– git config --global user.name "Bugs Bunny"
– git config --global user.email bugs@gmail.com
– You can call git config –list to verify these are set.
• Set the editor that is used for writing commit messages:
– git config --global core.editor nano
• (it is vim by default)
Creating a Git repo
• To create a new local Git repo in your current directory:
– git init
• This will create a .git directory in your current directory.
• Then you can commit files in that directory into the repo.
– git add filename
– git commit –m "commit message“
• To clone a remote repo to your current directory:
– git clone url localDirectoryName
• This will create the given local directory, containing a working copy of
the files from the repo, and a .git directory (used to hold the
staging area and your actual local repo)
GIT Commands
Command Description
git clone url [dir] copy a Git repository so you can add to it
git add file adds file contents to the staging area
git commit records a snapshot of the staging area
git status view the status of your files in the working
directory and staging area
git diff shows diff of what is staged and what is
modified but unstaged
git help [command] get help info about a particular command
git pull fetch from a remote repo and try to merge
into the current branch
git push push your new branches and data to a remote
repository
Others:init, reset, branch, checkout, merge, log, tag
Add and commit a file
• The first time we ask a file to be tracked, and every time
before we commit a file, we must add it to the staging area:
– git add Hello.java Goodbye.java
•Takes a snapshot of these files, adds them to the staging area. staging area" so it will
be part of the next commit.
• In older VCS, "add" means "start tracking this file." In Git, "add” means "add to
staging area" so it will be part of the next commit.
• To move staged changes into the repo, we commit:
– git commit –m "Fixing bug #22“
• To undo changes on a file before you have committed it:
– git reset HEAD -- filename (unstages the file)
– git checkout -- filename (undoes your changes)
– All these commands are acting on your local version of repo.
Viewing/undoing changes
• To view status of files in working directory and staging area:
– git status or git status –s (short version)
• To see what is modified but unstaged:
– git diff
• To see a list of staged changes:
– git diff –cached
To see a log of all changes in your local repo:
– git log or git log --oneline (shorter version)
1677b2d Edited first line of readme
258efa7 Added line to readme
0e52da7 Initial commit
• git log -5 (to show only the 5 most recent updates), etc.
An example workflow
[rea@attu1 superstar]$ vi rea.txt
[rea@attu1 superstar]$ git status
no changes added to commit
(use "git add" and/or "git commit -a")
[rea@attu1 superstar]$ git status -s
M rea.txt
[rea@attu1 superstar]$ git diff
diff --git a/rea.txt b/rea.txt
[rea@attu1 superstar]$ git add rea.txt
[rea@attu1 superstar]$ git status
# modified: rea.txt
[rea@attu1 superstar]$ git diff --cached
diff --git a/rea.txt b/rea.txt
[rea@attu1 superstar]$ git commit -m "Created new text file"
Branching and merging
Git uses branching heavily to switch between multiple tasks.
• To create a new local branch:
– git branch name
• To list all local branches: (* = current branch)
– git branch
• To switch to a given local branch:
– git checkout branchname
• To merge changes from a branch into the local master:
– git checkout master
– git merge branchname
Merge conflicts
• The conflicting file will contain <<< and >>> sections to
indicate where Git was unable to resolve a conflict:
<<<<<<< HEAD:index.html
<div id="footer">todo: message here</div> branch 1's version
=======
<div id="footer">
thanks for visiting our site branch 2’s version
</div>
>>>>>>>SpecialBranch:index.html
• Find all such sections, and edit them to the proper state
(whichever of the two versions is newer /better / more correct).
Interaction With Remote Repo
• Push your local changes to the remote repo.
• Pull from remote repo to get most recent changes.
– (fix conflicts if necessary, add/commit them to your local repo)
• To fetch the most recent updates from the remote repo into
your local repo, and put them into your working directory:
– git pull origin master
• To put your changes from your local repo in the remote repo:
– git push origin master
What is GitHub?
• GitHub.com is a site for online storage of Git repositories.
– You can create a remote repo there and push code to it.
– Many open source projects use it, such as the Linux kernel.
– You can get free space for open source projects,
or you can pay for private projects.
• Free private repos for educational use: github.com/edu
• Do I always have to use GitHub to use Git?
– Answer: No! You can use Git locally for your own purposes.
– Or you or someone else could set up a server to share files.
– Or you could share a repo with users on the same file system, as
long everyone has the needed file permissions.
GIT.pptx

More Related Content

Similar to GIT.pptx

Git hub
Git hubGit hub
Git hub
Nitin Goel
 
Git and github introduction
Git and github introductionGit and github introduction
Git and github introduction
John(Qiang) Zhang
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
DivineOmega
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
Arashdeepkaur16
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
GIT_Overview.
GIT_Overview.GIT_Overview.
GIT_Overview.
Mithilesh Singh
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
Geoff Hoffman
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
Kishor Kumar
 
Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
Naveen Pandey
 
GIT In Detail
GIT In DetailGIT In Detail
GIT In Detail
Haitham Raik
 
Learning git
Learning gitLearning git
Learning git
Sid Anand
 
Mini-training: Let’s Git It!
Mini-training: Let’s Git It!Mini-training: Let’s Git It!
Mini-training: Let’s Git It!
Betclic Everest Group Tech Team
 
Introduction into Git
Introduction into GitIntroduction into Git
Introduction into Git
Serhii Kartashov
 
Git introduction
Git introductionGit introduction
Git introduction
satyendrajaladi
 
Introduction to git & GitHub
Introduction to git & GitHubIntroduction to git & GitHub
Introduction to git & GitHub
Poornachandrakashi
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
Pablo Quiroga
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
Pablo Quiroga
 
git and github-1.pptx
git and github-1.pptxgit and github-1.pptx
git and github-1.pptx
tnscharishma
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git Migration
Manish Chakravarty
 

Similar to GIT.pptx (20)

Git hub
Git hubGit hub
Git hub
 
Git and github introduction
Git and github introductionGit and github introduction
Git and github introduction
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Git training (basic)
Git training (basic)Git training (basic)
Git training (basic)
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
GIT_Overview.
GIT_Overview.GIT_Overview.
GIT_Overview.
 
Git 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using GitGit 101 - Crash Course in Version Control using Git
Git 101 - Crash Course in Version Control using Git
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Git training v10
Git training v10Git training v10
Git training v10
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
 
GIT In Detail
GIT In DetailGIT In Detail
GIT In Detail
 
Learning git
Learning gitLearning git
Learning git
 
Mini-training: Let’s Git It!
Mini-training: Let’s Git It!Mini-training: Let’s Git It!
Mini-training: Let’s Git It!
 
Introduction into Git
Introduction into GitIntroduction into Git
Introduction into Git
 
Git introduction
Git introductionGit introduction
Git introduction
 
Introduction to git & GitHub
Introduction to git & GitHubIntroduction to git & GitHub
Introduction to git & GitHub
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
Demystifying Git
Demystifying GitDemystifying Git
Demystifying Git
 
git and github-1.pptx
git and github-1.pptxgit and github-1.pptx
git and github-1.pptx
 
Subversion to Git Migration
Subversion to Git MigrationSubversion to Git Migration
Subversion to Git Migration
 

Recently uploaded

road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
ydteq
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 

Recently uploaded (20)

road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
一比一原版(UofT毕业证)多伦多大学毕业证成绩单如何办理
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 

GIT.pptx

  • 2. Learning Objectives • How git creates a mini-filesystem in your directory • What commit, push, pull do • The elements of the basic git workflow • How git allows you to work across multiple computers • How git allows you and a partner to work together
  • 3. Git is a distributed version-control system • You keep your files in a repository on your local machine. • You synchronize your repository with a repository on a server. • If you move from one machine to another, you can pick up the changes by synchronizing with the server. • If your partner uploads some changes to your files, you can pick those up by synchronizing with the server.
  • 4. Why Git? • Over 70% of developers use Git! • Developers can work together from anywhere in the world. • Developers can see the full history of the project. • Developers can revert to earlier versions of a project.
  • 5. GIT Introduction • Created by Linus Torvalds, creator of Linux, in 2005 – Came out of Linux development community – Designed to do version control on Linux kernel • Goals of Git: – Speed – Support for non-linear development (thousands of parallel branches) – Fully distributed – Able to handle large projects efficiently
  • 6. Git is a Distributed Version-control System • Terminology: In git-speak, a “version” is called a “commit.” • Git keeps track of the history of your commits, so you can go back and look at earlier versions, or just give up on the current version and go back some earlier version.
  • 7. Centralized VCS In Subversion, CVS, Perforce, etc. A central server repository (repo) holds the "official copy" of the code – the server maintains the sole version history of the repo • You make "checkouts" of it to your local copy – you make local modifications – your changes are not versioned • When you're done, you "check in" back to the server – your checkin increments the repo's version
  • 8. GIT Snapshots • Centralized VCS like Subversion track version data on each individual file. • Git keeps "snapshots" of the entire state of the project. – Each checkin version of the overall code has a copy of each file in it. – Some files change on a given checkin, some do not. – More redundancy, but faster. Subversion GIT
  • 9. Local Git Areas • In your local copy on git, files can be: – In your local repo • (committed) – Checked out and modified, but not yet committed • (working copy) – Or, in-between, in a "staging" area • Staged files are ready to be committed. • A commit saves a snapshot of all staged state. Committed Files Staged Files Unmodified/modifie d Files
  • 11. Git Commit Checksums • In Subversion each modification to the central repo increments the version # of the overall repo. – In Git, each user has their own copy of the repo, and commits changes to their local copy of the repo before pushing to the central server. – So Git generates a unique SHA-1 hash (40 character string of hex digits) for every commit. – Refers to commits by this ID rather than a version number – Often we only see the first 7 characters: • 1677b2d Edited first line of readme • 258efa7 Added line to readme • 0e52da7 Initial commit
  • 12. Initial Git configuration • Set the name and email for Git to use when you commit: – git config --global user.name "Bugs Bunny" – git config --global user.email bugs@gmail.com – You can call git config –list to verify these are set. • Set the editor that is used for writing commit messages: – git config --global core.editor nano • (it is vim by default)
  • 13. Creating a Git repo • To create a new local Git repo in your current directory: – git init • This will create a .git directory in your current directory. • Then you can commit files in that directory into the repo. – git add filename – git commit –m "commit message“ • To clone a remote repo to your current directory: – git clone url localDirectoryName • This will create the given local directory, containing a working copy of the files from the repo, and a .git directory (used to hold the staging area and your actual local repo)
  • 14. GIT Commands Command Description git clone url [dir] copy a Git repository so you can add to it git add file adds file contents to the staging area git commit records a snapshot of the staging area git status view the status of your files in the working directory and staging area git diff shows diff of what is staged and what is modified but unstaged git help [command] get help info about a particular command git pull fetch from a remote repo and try to merge into the current branch git push push your new branches and data to a remote repository Others:init, reset, branch, checkout, merge, log, tag
  • 15. Add and commit a file • The first time we ask a file to be tracked, and every time before we commit a file, we must add it to the staging area: – git add Hello.java Goodbye.java •Takes a snapshot of these files, adds them to the staging area. staging area" so it will be part of the next commit. • In older VCS, "add" means "start tracking this file." In Git, "add” means "add to staging area" so it will be part of the next commit. • To move staged changes into the repo, we commit: – git commit –m "Fixing bug #22“ • To undo changes on a file before you have committed it: – git reset HEAD -- filename (unstages the file) – git checkout -- filename (undoes your changes) – All these commands are acting on your local version of repo.
  • 16. Viewing/undoing changes • To view status of files in working directory and staging area: – git status or git status –s (short version) • To see what is modified but unstaged: – git diff • To see a list of staged changes: – git diff –cached To see a log of all changes in your local repo: – git log or git log --oneline (shorter version) 1677b2d Edited first line of readme 258efa7 Added line to readme 0e52da7 Initial commit • git log -5 (to show only the 5 most recent updates), etc.
  • 17. An example workflow [rea@attu1 superstar]$ vi rea.txt [rea@attu1 superstar]$ git status no changes added to commit (use "git add" and/or "git commit -a") [rea@attu1 superstar]$ git status -s M rea.txt [rea@attu1 superstar]$ git diff diff --git a/rea.txt b/rea.txt [rea@attu1 superstar]$ git add rea.txt [rea@attu1 superstar]$ git status # modified: rea.txt [rea@attu1 superstar]$ git diff --cached diff --git a/rea.txt b/rea.txt [rea@attu1 superstar]$ git commit -m "Created new text file"
  • 18. Branching and merging Git uses branching heavily to switch between multiple tasks. • To create a new local branch: – git branch name • To list all local branches: (* = current branch) – git branch • To switch to a given local branch: – git checkout branchname • To merge changes from a branch into the local master: – git checkout master – git merge branchname
  • 19. Merge conflicts • The conflicting file will contain <<< and >>> sections to indicate where Git was unable to resolve a conflict: <<<<<<< HEAD:index.html <div id="footer">todo: message here</div> branch 1's version ======= <div id="footer"> thanks for visiting our site branch 2’s version </div> >>>>>>>SpecialBranch:index.html • Find all such sections, and edit them to the proper state (whichever of the two versions is newer /better / more correct).
  • 20. Interaction With Remote Repo • Push your local changes to the remote repo. • Pull from remote repo to get most recent changes. – (fix conflicts if necessary, add/commit them to your local repo) • To fetch the most recent updates from the remote repo into your local repo, and put them into your working directory: – git pull origin master • To put your changes from your local repo in the remote repo: – git push origin master
  • 21. What is GitHub? • GitHub.com is a site for online storage of Git repositories. – You can create a remote repo there and push code to it. – Many open source projects use it, such as the Linux kernel. – You can get free space for open source projects, or you can pay for private projects. • Free private repos for educational use: github.com/edu • Do I always have to use GitHub to use Git? – Answer: No! You can use Git locally for your own purposes. – Or you or someone else could set up a server to share files. – Or you could share a repo with users on the same file system, as long everyone has the needed file permissions.