SlideShare a Scribd company logo
1 of 61
Introduction to Git and GitHub
Venkat Malladi
Outline
I. Introduction to Git
A. What is Git?
B. Git workflow: Creating a new repo
C. HEAD
D. Basic Git commands
E. Concept of branches
F. Creating a branch/switching between branches
G. Merging branches and resolving conflicts
H. Concept of stashing
II. Introduction to GitHub
A. What is GitHub? Basic GitHub concepts
B. GitHub in practice: Distributed version control
C. Cloning a remote repo
D. Fetching/Pushing to a remote repo
E. Collaborating using Git and GitHub
What is a ‘version control system’?
• a way to manage files and directories
• track changes over time
• recall previous versions
• ‘source control’ is a subset of a VCS.
What is Git?
What is Git?
• created by Linus Torvalds, April 2005
• a command line version control program
• uses checksums to ensure data integrity
• cross-platform
• open source, free
• distributed version control
Distributed version control
• No central server
• Every developer is a client, the server and the repository
Source: http://bit.ly/1SH4E23
Git distributed version control
• no need to connect to central server
• can work without internet connection
• no single failure point
• developers can work independently and merge their work later
• every copy of a Git repository can serve either as the server or as a
client and has complete history
• Git tracks changes, not versions
• Bunch of little change sets floating around
What is a repository?
• “repo” = repository
• usually used to organize a single project
• repos can contain folders and files, images, videos,
spreadsheets, and data sets – anything your project needs
Git uses a three-tree architecture
Staging index
Working copy
Repository
checkout
add
commit
Before starting to use git
• Setup your name and email so others can know who committed
changes.
• git config - -global user.name ”name”
• git config - -global user.email ”email”
Note: set for all repositories on your computer
• git config - -local user.email ”email”
Note: can set differently for each repository
A simple Git workflow
1. Initialize a new project in a directory:
git init
2. Add a file using a text editor to the directory
3. Add every change that has been made to the directory:
git add <filename>.
4. Commit the change to the repo:
git commit –m “important message here”
After initializing a new git repo…
add
commit
Make changes to files
Add local changes
Commit changes with
message
Staging index
Working copy
Repository
Creating a new repository
• git init
• git add <filename>
• git commit –m “important message here”
Commit messages
• Tell what it does (present tense)
• Single line summary followed by blank space followed by more
complete description
• Keep lines to <= 72 characters
• Ticket or bug number helps
Commit Messages Structure
Short (50 chars or less) summary of changes
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of an email and the rest of the text as the body. The blank
line separating the summary from the body is critical (unless you omit
the body entirely); tools like rebase can get confused if you run the
two together.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded by a
single space, with blank lines in between, but conventions vary here
Source:http://git-scm.com/book/ch5-2.html
Good and bad examples
Bad: “Typo fix”
Good: “Add missing / in CSS section”
Bad: “Fix syntax”
Good: “Fix miscellaneous PEP8 issues”
How to see what was done
• git log
Checksums
generated by
SHA1
encryption
algorithm
“SHAs”
The HEAD pointer
• points to a specific commit in repo
• as new commits are made, the pointer changes
• HEAD always points to the “tip” of the currently c
HEAD
Master
f30ab34ac298ca9
Which files were changed and
where do they sit in the three tree?
• git status – allows one to see where files are in the three tree scheme
Repo
Working
copy
Staging
index
add
commit
Committing and adding message
• git commit -a
• Allows one to add to staging index and commit at the same time
• Grabs everything in working directory
• Files not tracked or being deleted are not included
• git diff – compares changes to files between repo and working
directory
What changed in working directory?
Note: git diff --staged - compares staging index to repo
Note: git diff filename can be used as well
Line numbers in file
Removed
Added
Repo
Working
copy
Staging
index
add
commit
Difference between commits
• git diff commit_1 commit_2
When using checksum of older commit, will show you all changes
compared to those in your working directory
Deleting files from the repo
• git rm filename.txt
• moves deleted file change to staging
area
• It is not enough to delete the file in
your working directory. You must
commit the change.
Repo
Working
copy
Staging
index
add
commit
Moving (renaming) files
• git mv filename1.txt filename2.txt
Note: File file1.txt was committed to repo earlier.
Repo
Working
copy
Staging
index
add
commit
• git init
• git status
• git log
• git add
• git commit
• git diff
• git rm
• git mv
Common workflow
Repo
Working
copy
Staging
index
add
commit
What if I want to undo changes
made to working directory?
• git checkout something
(where “something” is a file or an entire branch)
• git checkout will grab the file from the repo removing
all changes since last commit
• Example: git checkout -- file1.txt
(“checkout file ‘file1.txt’ from the current branch”)
checkout
Repo
Working
copy
Staging
index
add
commit
What if I want to undo changes
added to staging area?
• git reset HEAD filename.txt
reset
Repo
Working
copy
Staging
index
add
commit
Obtain older versions
• git checkout SHA1 -- filename.txt
Note: Checking out older commits places them into the staging area
checkout
Repo
Working
copy
Staging
index
add
commit
Branches in Git
• allows one to try new ideas
• If an idea doesn’t work, throw away the branch. Don’t have to undo
many changes to master branch
• If it does work, merge ideas into master branch.
• Note: There is only one working directory
Branching and merging example
HEAD
f30ab34ac298ca9
52ef3 S32d3
mN34i
HEAD
master
test_branch
merge
Source: http://hades.github.io/2010/01/git-your-friend-not-foe-vol-2-
branches/
What branch am I on?
• git branch
How do I create a new branch?
• git checkout -b new_branch_name
Note: At this point, both HEADs of the branches are pointing to the same
commit (that of master)
How do I switch branches?
• git checkout branch_name
At this point, one can switch between branches, making commits, etc. in either
branch, while the two stay separate from one another.
Note: In order to switch to another branch, your current working directory
must be clean (no conflicts, resulting in data loss).
Comparing branches
• git diff first_branch..second_branch
How do I merge a branch?
• git merge branch_to_merge
From the branch into which you want to merge another branch….
Note: Always have a clean working directory when merging
“fast-forward” merge occurs when HEAD of master
branch is seen when looking back
“recursive” merge occurs by looking back and combining
ancestors to resolve merge
34ac298ca9
52ef3 S32d3
mN34i
f30ab34ac298ca9
52ef3 S32d3
mN34i
Merge conflicts
What if there are two changes to same line in two different commits?
apple
master new_feature
banana
file1.txt file1.txt
Resolving merge conflicts
Git will notate the conflict in the files!
Solutions:
1. Abort the merge using git merge –abort
2. Manually fix the conflict
Graphing merge history
• git log --graph --oneline --all --decorate
Tips to reduce merge pain
• merge often
• keep commits small/focused
• bring changes occurring to master into your branch frequently
(“tracking”)
Renaming and deleting branches
• git branch –m/--move old_name new_name
• git branch –d branch_name
Note: Must not be in branch_name
Note: Must not have commits in branch_name unmerged in branch
from which you are deleting
• git branch –D branch_name
Note: If you are really sure that you want to delete branch with
commits
Fast context switching
• git stash
Allows you to save your work during work.
Using git stash will allow you to maintain the state of your current working
directory and saves it to an temporary index that you can reapply later.
Repo
Working
copy
Staging
index
add
commit
stash
Stashing
index
Note: Stashing is used for switching quickly between
branches when you have to work on multiple
different tasks. Don’t leave the code in stash
for a long period of time.
Stashing your changes
• git stash save message
Note: if you don’t use a message comment, git automatically creates it
from the last commit message. This can be confusing and lead to
errors.
• git stash list
Note: shows your list of stashes, similar to git log
Recovering your changes
• git stash pop index
Note: throws away the stash index after applying changes to working
directory
• git stash apply index
Note: leaves stash in index list, but applies changes to working
directory
Branching from stash
• git stash branch branch_name index
Note: If you plan on working on a new feature for a long time period,
create a branch from stashed changes
What is ?
What is GitHub
GitHub
• a platform to host code repositories
• http://github.com
• launched in 2007
• most popular Git host
• allows users to collaborate on projects from anywhere
• GitHub makes git social!
• Free to start (can pay for private repositories and additional
features)
Source: https://medium.com/@abhishekj/an-intro-to-git-and-github-1a0e2c7e3
Copying (cloning) files from remote
repo to local machine
• git clone URL <new_dir_name>
• HTTPS
• SSH
How do I link my local repo to a remote
repo?
• git remote add <alias> <URL>
Note: This just establishes a connection…no files are copied/moved
Note: Yes! You may have more than one remote linked to your local
directory!
Which remotes am I linked to?
• git remote -v
Pushing to a remote repo
• git push remote_name branch_name
Getting changes from a remote repo
• git fetch remote_repo_name
• Fetch in no way changes a your working dir or
any commits that you’ve made.
• git merge must be done to merge fetched changes
into local branch
• git pull remote_repo_name
• Fetch and merge changes to local branch and
working directory
Tagging
• git tag
• Git has the ability to tag specific points in history as being
important, such as releases versions
(v.1.0, 2.0, …)
Types of tags
Two types of tags:
• lightweight – a pointer to a specific comment – basically a SHA
stored in a file
git tag tag_name
• annotated – a full object stored in the Git database –
SHA, tagger name, email, date, message and
can be signed and verified with GNU Privacy Guard (GPG)
git tag –a tag_name –m “message”
Issue Tracking
Good resources
• Git from Git: https://git-scm.com/book/en/v2
• A number of easy-to-understand guides by the GitHub folks:
https://guides.github.com
• Try Github: https://try.github.io/
• Bitbucket, alternative code hosting: https://bitbucket.org/

More Related Content

What's hot

What's hot (20)

Git basic
Git basicGit basic
Git basic
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
git and github
git and githubgit and github
git and github
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git basics
Git basicsGit basics
Git basics
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git commands
Git commandsGit commands
Git commands
 
Github basics
Github basicsGithub basics
Github basics
 
Git slides
Git slidesGit slides
Git slides
 
Introduction to Git and GitHub Part 1
Introduction to Git and GitHub Part 1Introduction to Git and GitHub Part 1
Introduction to Git and GitHub Part 1
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git
GitGit
Git
 
Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 

Viewers also liked

Continuos integration patterns
Continuos integration patternsContinuos integration patterns
Continuos integration patterns
Vikas Gupta
 
Sys05 uso consapevole di git - beyond the basic
Sys05   uso consapevole di git - beyond the basicSys05   uso consapevole di git - beyond the basic
Sys05 uso consapevole di git - beyond the basic
DotNetCampus
 
Introduzione a GIT - Laboratorio di Web Design 2014/15
Introduzione a GIT - Laboratorio di Web Design 2014/15Introduzione a GIT - Laboratorio di Web Design 2014/15
Introduzione a GIT - Laboratorio di Web Design 2014/15
Giovanni Buffa
 

Viewers also liked (20)

Git Tutorial 教學
Git Tutorial 教學Git Tutorial 教學
Git Tutorial 教學
 
Getting Git Right
Getting Git RightGetting Git Right
Getting Git Right
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
 
Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners Git 101: Git and GitHub for Beginners
Git 101: Git and GitHub for Beginners
 
Git Branching Model
Git Branching ModelGit Branching Model
Git Branching Model
 
Git and Github
Git and GithubGit and Github
Git and Github
 
Getting Git
Getting GitGetting Git
Getting Git
 
Intro to git
Intro to gitIntro to git
Intro to git
 
GdG DevFestMed 2016 - 06/11/2016
GdG DevFestMed 2016 - 06/11/2016GdG DevFestMed 2016 - 06/11/2016
GdG DevFestMed 2016 - 06/11/2016
 
Team Collaboration with GitHub
Team Collaboration with GitHubTeam Collaboration with GitHub
Team Collaboration with GitHub
 
Maven 2 Introduction
Maven 2 IntroductionMaven 2 Introduction
Maven 2 Introduction
 
VNPAY Git Seminar
VNPAY Git SeminarVNPAY Git Seminar
VNPAY Git Seminar
 
Git 더하기 GitHub(Git클라이언트 활용) / Getting started with git+github
Git 더하기 GitHub(Git클라이언트 활용) / Getting started with git+githubGit 더하기 GitHub(Git클라이언트 활용) / Getting started with git+github
Git 더하기 GitHub(Git클라이언트 활용) / Getting started with git+github
 
Continuos integration patterns
Continuos integration patternsContinuos integration patterns
Continuos integration patterns
 
Sys05 uso consapevole di git - beyond the basic
Sys05   uso consapevole di git - beyond the basicSys05   uso consapevole di git - beyond the basic
Sys05 uso consapevole di git - beyond the basic
 
Perchè Git?
Perchè Git?Perchè Git?
Perchè Git?
 
Introduzione a GIT - Laboratorio di Web Design 2014/15
Introduzione a GIT - Laboratorio di Web Design 2014/15Introduzione a GIT - Laboratorio di Web Design 2014/15
Introduzione a GIT - Laboratorio di Web Design 2014/15
 
GITT (part 1 of 2)
GITT (part 1 of 2)GITT (part 1 of 2)
GITT (part 1 of 2)
 
Git–SVN
Git–SVNGit–SVN
Git–SVN
 
GitSlides
GitSlidesGitSlides
GitSlides
 

Similar to Intro to git and git hub

Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
Robert Lee-Cann
 

Similar to Intro to git and git hub (20)

Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Git_new.pptx
Git_new.pptxGit_new.pptx
Git_new.pptx
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Git Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptx
 
Let's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHubLet's Git this Party Started: An Introduction to Git and GitHub
Let's Git this Party Started: An Introduction to Git and GitHub
 
Learn Git form Beginners to Master
Learn Git form Beginners to MasterLearn Git form Beginners to Master
Learn Git form Beginners to Master
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
 
[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with Git[2015/2016] Collaborative software development with Git
[2015/2016] Collaborative software development with Git
 
Git hub
Git hubGit hub
Git hub
 
Git and GitHub (1).pptx
Git and GitHub (1).pptxGit and GitHub (1).pptx
Git and GitHub (1).pptx
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Beginner's Guide to Version Control with Git
Beginner's Guide to Version Control with GitBeginner's Guide to Version Control with Git
Beginner's Guide to Version Control with Git
 
Git 101
Git 101Git 101
Git 101
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
Git for developers
Git for developersGit for developers
Git for developers
 

Recently uploaded

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 

Recently uploaded (20)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
Computer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to ComputersComputer Lecture 01.pptxIntroduction to Computers
Computer Lecture 01.pptxIntroduction to Computers
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptxA CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
A CASE STUDY ON CERAMIC INDUSTRY OF BANGLADESH.pptx
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Introduction to Serverless with AWS Lambda
Introduction to Serverless with AWS LambdaIntroduction to Serverless with AWS Lambda
Introduction to Serverless with AWS Lambda
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 

Intro to git and git hub

  • 1. Introduction to Git and GitHub Venkat Malladi
  • 2. Outline I. Introduction to Git A. What is Git? B. Git workflow: Creating a new repo C. HEAD D. Basic Git commands E. Concept of branches F. Creating a branch/switching between branches G. Merging branches and resolving conflicts H. Concept of stashing II. Introduction to GitHub A. What is GitHub? Basic GitHub concepts B. GitHub in practice: Distributed version control C. Cloning a remote repo D. Fetching/Pushing to a remote repo E. Collaborating using Git and GitHub
  • 3. What is a ‘version control system’? • a way to manage files and directories • track changes over time • recall previous versions • ‘source control’ is a subset of a VCS.
  • 5. What is Git? • created by Linus Torvalds, April 2005 • a command line version control program • uses checksums to ensure data integrity • cross-platform • open source, free • distributed version control
  • 6. Distributed version control • No central server • Every developer is a client, the server and the repository Source: http://bit.ly/1SH4E23
  • 7. Git distributed version control • no need to connect to central server • can work without internet connection • no single failure point • developers can work independently and merge their work later • every copy of a Git repository can serve either as the server or as a client and has complete history • Git tracks changes, not versions • Bunch of little change sets floating around
  • 8. What is a repository? • “repo” = repository • usually used to organize a single project • repos can contain folders and files, images, videos, spreadsheets, and data sets – anything your project needs
  • 9. Git uses a three-tree architecture Staging index Working copy Repository checkout add commit
  • 10. Before starting to use git • Setup your name and email so others can know who committed changes. • git config - -global user.name ”name” • git config - -global user.email ”email” Note: set for all repositories on your computer • git config - -local user.email ”email” Note: can set differently for each repository
  • 11. A simple Git workflow 1. Initialize a new project in a directory: git init 2. Add a file using a text editor to the directory 3. Add every change that has been made to the directory: git add <filename>. 4. Commit the change to the repo: git commit –m “important message here”
  • 12. After initializing a new git repo… add commit Make changes to files Add local changes Commit changes with message Staging index Working copy Repository
  • 13. Creating a new repository • git init • git add <filename> • git commit –m “important message here”
  • 14. Commit messages • Tell what it does (present tense) • Single line summary followed by blank space followed by more complete description • Keep lines to <= 72 characters • Ticket or bug number helps
  • 15. Commit Messages Structure Short (50 chars or less) summary of changes More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together. Further paragraphs come after blank lines. - Bullet points are okay, too - Typically a hyphen or asterisk is used for the bullet, preceded by a single space, with blank lines in between, but conventions vary here Source:http://git-scm.com/book/ch5-2.html
  • 16. Good and bad examples Bad: “Typo fix” Good: “Add missing / in CSS section” Bad: “Fix syntax” Good: “Fix miscellaneous PEP8 issues”
  • 17. How to see what was done • git log
  • 19. The HEAD pointer • points to a specific commit in repo • as new commits are made, the pointer changes • HEAD always points to the “tip” of the currently c
  • 21. Which files were changed and where do they sit in the three tree? • git status – allows one to see where files are in the three tree scheme Repo Working copy Staging index add commit
  • 22. Committing and adding message • git commit -a • Allows one to add to staging index and commit at the same time • Grabs everything in working directory • Files not tracked or being deleted are not included
  • 23. • git diff – compares changes to files between repo and working directory What changed in working directory? Note: git diff --staged - compares staging index to repo Note: git diff filename can be used as well Line numbers in file Removed Added Repo Working copy Staging index add commit
  • 24. Difference between commits • git diff commit_1 commit_2 When using checksum of older commit, will show you all changes compared to those in your working directory
  • 25. Deleting files from the repo • git rm filename.txt • moves deleted file change to staging area • It is not enough to delete the file in your working directory. You must commit the change. Repo Working copy Staging index add commit
  • 26. Moving (renaming) files • git mv filename1.txt filename2.txt Note: File file1.txt was committed to repo earlier. Repo Working copy Staging index add commit
  • 27. • git init • git status • git log • git add • git commit • git diff • git rm • git mv Common workflow Repo Working copy Staging index add commit
  • 28. What if I want to undo changes made to working directory? • git checkout something (where “something” is a file or an entire branch) • git checkout will grab the file from the repo removing all changes since last commit • Example: git checkout -- file1.txt (“checkout file ‘file1.txt’ from the current branch”) checkout Repo Working copy Staging index add commit
  • 29. What if I want to undo changes added to staging area? • git reset HEAD filename.txt reset Repo Working copy Staging index add commit
  • 30. Obtain older versions • git checkout SHA1 -- filename.txt Note: Checking out older commits places them into the staging area checkout Repo Working copy Staging index add commit
  • 31. Branches in Git • allows one to try new ideas • If an idea doesn’t work, throw away the branch. Don’t have to undo many changes to master branch • If it does work, merge ideas into master branch. • Note: There is only one working directory
  • 32. Branching and merging example HEAD f30ab34ac298ca9 52ef3 S32d3 mN34i HEAD master test_branch merge
  • 34. What branch am I on? • git branch
  • 35. How do I create a new branch? • git checkout -b new_branch_name Note: At this point, both HEADs of the branches are pointing to the same commit (that of master)
  • 36. How do I switch branches? • git checkout branch_name At this point, one can switch between branches, making commits, etc. in either branch, while the two stay separate from one another. Note: In order to switch to another branch, your current working directory must be clean (no conflicts, resulting in data loss).
  • 37. Comparing branches • git diff first_branch..second_branch
  • 38. How do I merge a branch? • git merge branch_to_merge From the branch into which you want to merge another branch…. Note: Always have a clean working directory when merging
  • 39. “fast-forward” merge occurs when HEAD of master branch is seen when looking back “recursive” merge occurs by looking back and combining ancestors to resolve merge 34ac298ca9 52ef3 S32d3 mN34i f30ab34ac298ca9 52ef3 S32d3 mN34i
  • 40. Merge conflicts What if there are two changes to same line in two different commits? apple master new_feature banana file1.txt file1.txt
  • 41. Resolving merge conflicts Git will notate the conflict in the files! Solutions: 1. Abort the merge using git merge –abort 2. Manually fix the conflict
  • 42. Graphing merge history • git log --graph --oneline --all --decorate
  • 43. Tips to reduce merge pain • merge often • keep commits small/focused • bring changes occurring to master into your branch frequently (“tracking”)
  • 44. Renaming and deleting branches • git branch –m/--move old_name new_name • git branch –d branch_name Note: Must not be in branch_name Note: Must not have commits in branch_name unmerged in branch from which you are deleting • git branch –D branch_name Note: If you are really sure that you want to delete branch with commits
  • 45. Fast context switching • git stash Allows you to save your work during work. Using git stash will allow you to maintain the state of your current working directory and saves it to an temporary index that you can reapply later. Repo Working copy Staging index add commit stash Stashing index Note: Stashing is used for switching quickly between branches when you have to work on multiple different tasks. Don’t leave the code in stash for a long period of time.
  • 46. Stashing your changes • git stash save message Note: if you don’t use a message comment, git automatically creates it from the last commit message. This can be confusing and lead to errors. • git stash list Note: shows your list of stashes, similar to git log
  • 47. Recovering your changes • git stash pop index Note: throws away the stash index after applying changes to working directory • git stash apply index Note: leaves stash in index list, but applies changes to working directory
  • 48. Branching from stash • git stash branch branch_name index Note: If you plan on working on a new feature for a long time period, create a branch from stashed changes
  • 51. GitHub • a platform to host code repositories • http://github.com • launched in 2007 • most popular Git host • allows users to collaborate on projects from anywhere • GitHub makes git social! • Free to start (can pay for private repositories and additional features)
  • 53.
  • 54. Copying (cloning) files from remote repo to local machine • git clone URL <new_dir_name> • HTTPS • SSH
  • 55. How do I link my local repo to a remote repo? • git remote add <alias> <URL> Note: This just establishes a connection…no files are copied/moved Note: Yes! You may have more than one remote linked to your local directory! Which remotes am I linked to? • git remote -v
  • 56. Pushing to a remote repo • git push remote_name branch_name
  • 57. Getting changes from a remote repo • git fetch remote_repo_name • Fetch in no way changes a your working dir or any commits that you’ve made. • git merge must be done to merge fetched changes into local branch • git pull remote_repo_name • Fetch and merge changes to local branch and working directory
  • 58. Tagging • git tag • Git has the ability to tag specific points in history as being important, such as releases versions (v.1.0, 2.0, …)
  • 59. Types of tags Two types of tags: • lightweight – a pointer to a specific comment – basically a SHA stored in a file git tag tag_name • annotated – a full object stored in the Git database – SHA, tagger name, email, date, message and can be signed and verified with GNU Privacy Guard (GPG) git tag –a tag_name –m “message”
  • 61. Good resources • Git from Git: https://git-scm.com/book/en/v2 • A number of easy-to-understand guides by the GitHub folks: https://guides.github.com • Try Github: https://try.github.io/ • Bitbucket, alternative code hosting: https://bitbucket.org/

Editor's Notes

  1. One can log in in the morning and see what has been done and by who.
  2. Cat HEAD file in .git dir to see where HEAD is currently pointing.