SlideShare a Scribd company logo
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
Intro to git and git hub
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

Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Learning git
Learning gitLearning git
Learning git
Sid Anand
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
Arnaud Seilles
 
Introduction git
Introduction gitIntroduction git
Introduction git
Dian Sigit Prastowo
 
Git best practices workshop
Git best practices workshopGit best practices workshop
Git best practices workshop
Otto Kekäläinen
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
Lee Hanxue
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
GoogleDevelopersStud1
 
Github basics
Github basicsGithub basics
Github basics
Radoslav Georgiev
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
KMS Technology
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
Vikram SV
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
Yan Vugenfirer
 
Git flow Introduction
Git flow IntroductionGit flow Introduction
Git flow Introduction
David Paluy
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
Fran García
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
"FENG "GEORGE"" YU
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
Anurag Upadhaya
 
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
Rueful Robin
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
Nick Quaranto
 
Git & GitLab
Git & GitLabGit & GitLab
Git & GitLab
Gaurav Wable
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
Arulmurugan Rajaraman
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
Dilum Navanjana
 

What's hot (20)

Git training v10
Git training v10Git training v10
Git training v10
 
Learning git
Learning gitLearning git
Learning git
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Git best practices workshop
Git best practices workshopGit best practices workshop
Git best practices workshop
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Git and Github Session
Git and Github SessionGit and Github Session
Git and Github Session
 
Github basics
Github basicsGithub basics
Github basics
 
Git Version Control System
Git Version Control SystemGit Version Control System
Git Version Control System
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git flow Introduction
Git flow IntroductionGit flow Introduction
Git flow Introduction
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
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
 
Git Started With Git
Git Started With GitGit Started With Git
Git Started With Git
 
Git & GitLab
Git & GitLabGit & GitLab
Git & GitLab
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
 

Viewers also liked

Getting Git Right
Getting Git RightGetting Git Right
Getting Git Right
Sven Peters
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
littlebtc
 
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
HubSpot
 
Git Branching Model
Git Branching ModelGit Branching Model
Git Branching Model
Lemi Orhan Ergin
 
Git and Github
Git and GithubGit and Github
Git and Github
Wen-Tien Chang
 
Getting Git
Getting GitGetting Git
Getting Git
Scott Chacon
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
Panagiotis Papadopoulos
 
Intro to git
Intro to gitIntro to git
Intro to git
josh_cutler
 
GdG DevFestMed 2016 - 06/11/2016
GdG DevFestMed 2016 - 06/11/2016GdG DevFestMed 2016 - 06/11/2016
GdG DevFestMed 2016 - 06/11/2016
Gaetano Paternò
 
Team Collaboration with GitHub
Team Collaboration with GitHubTeam Collaboration with GitHub
Team Collaboration with GitHub
Kevin Pruett
 
Maven 2 Introduction
Maven 2 IntroductionMaven 2 Introduction
Maven 2 Introduction
Valentin Jacquemin
 
VNPAY Git Seminar
VNPAY Git SeminarVNPAY Git Seminar
VNPAY Git Seminar
Mr Slowly
 
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
Junyoung Lee
 
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
 
Perchè Git?
Perchè Git?Perchè Git?
Perchè Git?
Mauro Ferratello
 
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
 
GITT (part 1 of 2)
GITT (part 1 of 2)GITT (part 1 of 2)
GITT (part 1 of 2)
Ali Servet Donmez
 
Git–SVN
Git–SVNGit–SVN

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 and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
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
 

Similar to Intro to git and git hub

Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Git_new.pptx
Git_new.pptxGit_new.pptx
Git_new.pptx
BruceLee275640
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
Nguyen Van Hung
 
Introduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxIntroduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptx
Abdul Salam
 
Git Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptx
Eshaan35
 
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
Kim Moir
 
Learn Git form Beginners to Master
Learn Git form Beginners to MasterLearn Git form Beginners to Master
Learn Git form Beginners to Master
C. M. Abdullah Khan
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
Aditya Tiwari
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
Aditya Tiwari
 
Techoalien git
Techoalien gitTechoalien git
Techoalien git
Aditya Tiwari
 
[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
Ivano Malavolta
 
Git hub
Git hubGit hub
Git hub
Nitin Goel
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to git hub
Naveen Pandey
 
Git and GitHub (1).pptx
Git and GitHub (1).pptxGit and GitHub (1).pptx
Git and GitHub (1).pptx
BetelAddisu
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
Prakash Dantuluri
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
Bimal Jain
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
Peder Larson
 
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
 
Git 101
Git 101Git 101
Git 101
jayrparro
 

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
 
Introduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptxIntroduction to git and githhub with practicals.pptx
Introduction to git and githhub with practicals.pptx
 
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
 
Introduction to git hub
Introduction to git hubIntroduction to git hub
Introduction to 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
 

Recently uploaded

Time-State Analytics: MinneAnalytics 2024 Talk
Time-State Analytics: MinneAnalytics 2024 TalkTime-State Analytics: MinneAnalytics 2024 Talk
Time-State Analytics: MinneAnalytics 2024 Talk
Evan Chan
 
Chartered Cost Engineer ChCE certification.pdf
Chartered Cost Engineer ChCE certification.pdfChartered Cost Engineer ChCE certification.pdf
Chartered Cost Engineer ChCE certification.pdf
GAFM ACADEMY
 
ANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
ANATOMY OF SOA - Thomas Erl - Service Oriented ArchitectureANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
ANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
Divya Rajasekar
 
Technical Seminar of Mca computer vision .ppt
Technical Seminar of Mca computer vision .pptTechnical Seminar of Mca computer vision .ppt
Technical Seminar of Mca computer vision .ppt
AnkitaVerma776806
 
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
rawankhanlove256
 
Probability and Statistics by sheldon ross (8th edition).pdf
Probability and Statistics by sheldon ross (8th edition).pdfProbability and Statistics by sheldon ross (8th edition).pdf
Probability and Statistics by sheldon ross (8th edition).pdf
utkarshakusnake
 
The world of Technology Management MEM 814.pptx
The world of Technology Management MEM 814.pptxThe world of Technology Management MEM 814.pptx
The world of Technology Management MEM 814.pptx
engrasjadshahzad
 
Metal air battery presentation for online interview
Metal air battery presentation for online interviewMetal air battery presentation for online interview
Metal air battery presentation for online interview
muhammadhamza505998
 
Tutorial on MySQl and its basic concepts
Tutorial on MySQl and its basic conceptsTutorial on MySQl and its basic concepts
Tutorial on MySQl and its basic concepts
anishacotta2
 
OSHA LOTO training, LOTO, lock out tag out
OSHA LOTO training, LOTO, lock out tag outOSHA LOTO training, LOTO, lock out tag out
OSHA LOTO training, LOTO, lock out tag out
Ateeb19
 
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATAFINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
kevig
 
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptxOME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
shanmugamram247
 
Ludo system project report management .pdf
Ludo  system project report management .pdfLudo  system project report management .pdf
Ludo system project report management .pdf
Kamal Acharya
 
Sustainable construction is the use of renewable and recyclable materials in ...
Sustainable construction is the use of renewable and recyclable materials in ...Sustainable construction is the use of renewable and recyclable materials in ...
Sustainable construction is the use of renewable and recyclable materials in ...
RohitGhulanavar2
 
Red Hat Enterprise Linux Administration 9.0 RH134 pdf
Red Hat Enterprise Linux Administration 9.0 RH134 pdfRed Hat Enterprise Linux Administration 9.0 RH134 pdf
Red Hat Enterprise Linux Administration 9.0 RH134 pdf
mdfkobir
 
Metrology Book, Bachelors in Mechanical Engineering
Metrology Book, Bachelors in Mechanical EngineeringMetrology Book, Bachelors in Mechanical Engineering
Metrology Book, Bachelors in Mechanical Engineering
leakingvideo
 
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptxIE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
BehairyAhmed2
 
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagneEAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
idelewebmestre
 
Traffic Engineering-MODULE-1 vtu syllabus.pptx
Traffic Engineering-MODULE-1 vtu syllabus.pptxTraffic Engineering-MODULE-1 vtu syllabus.pptx
Traffic Engineering-MODULE-1 vtu syllabus.pptx
mailmad391
 
Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
sunnuchadda
 

Recently uploaded (20)

Time-State Analytics: MinneAnalytics 2024 Talk
Time-State Analytics: MinneAnalytics 2024 TalkTime-State Analytics: MinneAnalytics 2024 Talk
Time-State Analytics: MinneAnalytics 2024 Talk
 
Chartered Cost Engineer ChCE certification.pdf
Chartered Cost Engineer ChCE certification.pdfChartered Cost Engineer ChCE certification.pdf
Chartered Cost Engineer ChCE certification.pdf
 
ANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
ANATOMY OF SOA - Thomas Erl - Service Oriented ArchitectureANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
ANATOMY OF SOA - Thomas Erl - Service Oriented Architecture
 
Technical Seminar of Mca computer vision .ppt
Technical Seminar of Mca computer vision .pptTechnical Seminar of Mca computer vision .ppt
Technical Seminar of Mca computer vision .ppt
 
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Mysore 000XX00000 Provide Best And Top Girl Service And No1 in City
 
Probability and Statistics by sheldon ross (8th edition).pdf
Probability and Statistics by sheldon ross (8th edition).pdfProbability and Statistics by sheldon ross (8th edition).pdf
Probability and Statistics by sheldon ross (8th edition).pdf
 
The world of Technology Management MEM 814.pptx
The world of Technology Management MEM 814.pptxThe world of Technology Management MEM 814.pptx
The world of Technology Management MEM 814.pptx
 
Metal air battery presentation for online interview
Metal air battery presentation for online interviewMetal air battery presentation for online interview
Metal air battery presentation for online interview
 
Tutorial on MySQl and its basic concepts
Tutorial on MySQl and its basic conceptsTutorial on MySQl and its basic concepts
Tutorial on MySQl and its basic concepts
 
OSHA LOTO training, LOTO, lock out tag out
OSHA LOTO training, LOTO, lock out tag outOSHA LOTO training, LOTO, lock out tag out
OSHA LOTO training, LOTO, lock out tag out
 
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATAFINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
FINE-TUNING OF SMALL/MEDIUM LLMS FOR BUSINESS QA ON STRUCTURED DATA
 
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptxOME754 – INDUSTRIAL SAFETY - unit notes.pptx
OME754 – INDUSTRIAL SAFETY - unit notes.pptx
 
Ludo system project report management .pdf
Ludo  system project report management .pdfLudo  system project report management .pdf
Ludo system project report management .pdf
 
Sustainable construction is the use of renewable and recyclable materials in ...
Sustainable construction is the use of renewable and recyclable materials in ...Sustainable construction is the use of renewable and recyclable materials in ...
Sustainable construction is the use of renewable and recyclable materials in ...
 
Red Hat Enterprise Linux Administration 9.0 RH134 pdf
Red Hat Enterprise Linux Administration 9.0 RH134 pdfRed Hat Enterprise Linux Administration 9.0 RH134 pdf
Red Hat Enterprise Linux Administration 9.0 RH134 pdf
 
Metrology Book, Bachelors in Mechanical Engineering
Metrology Book, Bachelors in Mechanical EngineeringMetrology Book, Bachelors in Mechanical Engineering
Metrology Book, Bachelors in Mechanical Engineering
 
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptxIE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
IE-469-Lecture-Notes-3IE-469-Lecture-Notes-3.pptx
 
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagneEAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
EAAP2023 : Durabilité et services écosystémiques de l'élevage ovin de montagne
 
Traffic Engineering-MODULE-1 vtu syllabus.pptx
Traffic Engineering-MODULE-1 vtu syllabus.pptxTraffic Engineering-MODULE-1 vtu syllabus.pptx
Traffic Engineering-MODULE-1 vtu syllabus.pptx
 
Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in CityGirls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
Girls Call Chennai 000XX00000 Provide Best And Top Girl Service And No1 in City
 

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