SlideShare a Scribd company logo
Introduction to GIT
Muhil
What is GIT
• Version control system
• decentralised by nature
but can be used as
centralised by convention
Repo
Repo
Repo
Git Lifecycle
• Create
• Create a local repo or clone from existing
• Create a remote repo for centralised sharing (also called bare repositories)
• configure repository details, gitignore, remote repos
• Collaborate
• fetch,pull,commit,push changes
• branching
• merging vs rebasing
• Maintain
• iterate collaboration further sprints with tagging versions and releases
• optimize
Create
Bare Repo vs Repo
Bare repo Repo
No working copy
working copy checked out in the
directory
cannot edit directly edit commit and push changes
usually used for centralised
sharing for repositories
used for development on local
boxes
git init --bare {directory name} git init {directory name}
Remote Repository Services
• Used to host Bare repositories
• Main usage is as centralised repos for sharing
• Can be an online service
• Bitbucket, Github, AWS CodeCommit
• Can be a local service
• Gitlab
Create a local repo
• One time operation
• To create a repository in current directory
• git init
• To create a repository in specified directory
• git init {directory name}
• This creates and checks out a empty repository to which files can be
added.
• a hidden directory called .git in the specified or working directory as
applicable
Add a remote repo
• If the local repo is a new repo then we might need to add the remote repo setup for sharing
• git remote add {remotename} {remote path/URL}
• example
• git remote add origin https://github.com/user/repo.git
• we can have multiple remote repos to a local repo
• change a remote URL
• git remote set-url {remotename} {new remote url}
• rename a remote
• git remote rename {old name} {new name}
• list all remotes
• git remote -v
Clone a repo
• A repo can be cloned from a local machine or from a remote location to a specified
location
• the command structure is
• git clone <repo path> <local directory name>
• this can be done over ssh / https for remote repos and just by giving the path when
cloning in the same machine.
• if no local directory name is specified it clones into the current working directory as
with the above examples
• If need to clone to a specific directory , then need to specify the folder name at the
end of the command
• git clone https://github.com/username/repo.git /path/to/custom-directory-name
Configuring a Git repo
• The command structure usually is
• git config <option> <parameter> <value>
• the option can specify scope which can be local, global or system
• local is for that repo, whereas global is for that user and system is system wide
• git config --global user.email <email>
• git config --global user.name <name>
• local overrides global, global overrides system
• local config is in .git/config
• global is in ~/.gitconfig
• system is in /etc/gitconfig
Configuring a Git repo
• We can do a variety of manipulations with git config command
• some examples
• Tell Git who you are
• git config --global user.name "John Smith"
• git config --global user.email john@example.com
• Select your favourite text editor
• git config --global core.editor vim
• Ignore file permission changes for committing
• git config --global core.fileMode false
.gitignore
• this is used to ignore any files/folder from the repository
• a .gitignore file can have a rule ignoring a specific file or all files with an extension.
• It can be used even to ignore itself (i don’t recommend it though)
• example entries in the gitignore file
• debug.log
• *.log
• img/*
• !img/logo.png
• Highly useful for ignoring user uploaded content from filling up the repo and keep
the repo manageable
Collaborate
Committing changes
• We first need to stage any changes before committing.
• this can be done for all files changed
• git add .
• for specific files by
• git add {specific file name}
• To commit the changes
• git commit -m ‘message for commit’
To track and update changes
from/to remote
• check status of current local repo
• git status
• to update tracking from remote repo
• git fetch
• to pull changes from remote repo
• git pull {remote name} {branch name}
• to push changes
• git push {remote name} {branch name}
• git push --all
• git push --dry-run
Amending, Reverting and
Resetting a commit
• To amend a commit
• git commit --amend
• reverting
• when reverting it undoes a commit’s changes and creates a new commit
• git revert <commit>
• safer
• resetting
• resets your working copy to a particular commit undoing any other changes you have done
• git reset [--soft --hard] <commit>
• like in rebasing dangerous as public shared commits can get modified causing issues
• to discard any working copy changes resetting this is useful
• git reset --hard
Committing a deleted file
• Sometimes you need to delete a file from the repo
• This doesn’t get automatically staged when you do
git add .
• Need to specify that you need to stage deleted files
as well before committing
• git add -u .
Branching
• A variety of strategies available
• create branches for bugfixes, development of new features and any and all changes to codebase
• create new branch
• git branch {branch name}
• git checkout {branch name}
• these can be done with a single command as well
• git checkout -b {branch name}
• switch to an existing branch
• git checkout {branch name}
• list branches
• git branch (for local only)
• git branch -r (for remote only)
• git branch -a (for both)
Merging
• The branches need to be merged to the master
branch after testing for release.
• to merge
• switch to the branch that is to be merged into (ex)
master
• git checkout master
• merge the branch (ex) hotfix1223
• git merge hotfix1223
• to merge Pull requests can also be used for an
administrator to verify the changes in Remote repos
• when merging we might run into conflicts
Merge Conflicts
• Do a git status to find which file is
conflicting and open it
• A conflicting file will look like the example
on the side
• A conflict occurs when there are changes
from two branches on the same line
• in the example the footer line has been
changed on master and on the hot fix
branch
• All to more reason to NEVER do changes
on the master branch directly
• Also conflicts may occur when merging a
branch from a different developer to your
own branch
<<<<<<< HEAD:index.html
<div id="footer">contact :
support@muhilvannan.com</div>
=======
<div id="footer">
please contact us at
support@muhilvannan.com
</div>
>>>>>>> hotfix1223:index.html
Fixing Conflicts
<<<<<<< HEAD:index.html to=======
is the block on the master/ current branch
======= to >>>>>>> hotfix1223:index.html
is the block on the branch to merged
• these need to be replaced with the text as required.
• the replacing text can be from the current branch or from
the branch being merged or a combination of both
• make sure
<<<<<<< HEAD:index.html
=======
>>>>>>> hotfix1223:index.html
are removed fro the code as depicted in the right column
• save and commit
<<<<<<< HEAD:index.html
<div id="footer">contact : support@muhilvannan.com</div>
=======
<div id="footer">
please contact us at support@muhilvannan.com
</div>
>>>>>>> hotfix1223:index.html
<div id="footer">
please contact us at support@muhilvannan.com
</div>
replace with
Fixing Conflicts
• There are graphical tools for fixing merge conflicts
as well
• git mergetool
• you might need to configure the tool if not already
• git config --global merge.tool {mergetool name}
• kdiff3 and extmetge are very good tools
Rebasing
• Rebasing is the process of
moving a branch to a new
base commit
• Useful to do locally
• NOT SAFE for public history
repositories, as the history
might be modified and cause
issues with other developers
• The golden rule of git rebase
is to never use it on public
branches
• I would recommend Merge
instead of rebase just to
eliminate this issue so as to
never mistakenly change it
Maintain
Tagging
• With git you can tag an commit for easy finding and
downloading
• also useful for tagging release versions
• git tag -a {tag} -m ‘message'
• git tag -a {tag} {commit number}
• To checkout a branch and a tagged commit
• git checkout -b [branchname] [tagname]
Tagging
• to list tags
• git tag
• push tags to remote
• git push {remote name} --tags
• delete a tag
• git tag -d {tag}
• git push {remote name} --tags
Stashing
• Files not ready to be committed can be stashed.
• git stash
• git stash list
• git stash apply
Optimize a Git repo
• used to optimise git repo and clean up loose objects
• sometimes run along with usual git commands
• can also be run manually
• 'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune]
[—force]
GUI tools for git
• Sourcetree - mac & windows
• Tower - mac
• GitEye - linux
• Github for windows
• Github for mac
Things to note
• Git doesn’t maintain a folder structure if nothing
underneath it is gitted.
• files called empty should be added to the folder and
the repo for this purpose
• File permissions are usually gitted along with the
files and if you want to ignore any changes to file
permissions the repo needs to be configured
Useful Documentation Links
• https://help.github.com/articles/good-resources-for-learning-git-and-
github/
• https://www.atlassian.com/git/tutorials/setting-up-a-repository
• http://git-scm.com/doc
• https://git-scm.com/downloads/guis

More Related Content

What's hot

Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
Jim Yeh
 
Git more done
Git more doneGit more done
Git more done
Kwen Peterson
 
Git basic
Git basicGit basic
Git basic
Emran Ul Hadi
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
mobaires
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
Yoad Snapir
 
Git basics
Git basicsGit basics
Git basics
Denys Haryachyy
 
Git training v10
Git training v10Git training v10
Git training v10
Skander Hamza
 
Git hub
Git hubGit hub
Git hub
Nitin Goel
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
Nilay Binjola
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
Bimal Jain
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
DivineOmega
 
Working with Git
Working with GitWorking with Git
Working with Git
Sanghoon Hong
 
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of GitGit Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Nicola Costantino
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
Anurag Upadhaya
 
Git commands
Git commandsGit commands
Git commands
Viyaan Jhiingade
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of trouble
Jon Senchyna
 
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
Edureka!
 

What's hot (20)

Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Git more done
Git more doneGit more done
Git more done
 
Git basic
Git basicGit basic
Git basic
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Git basics
Git basicsGit basics
Git basics
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git hub
Git hubGit hub
Git hub
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash Course
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthrough
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 
Working with Git
Working with GitWorking with Git
Working with Git
 
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of GitGit Is A State Of Mind - The path to becoming a Master of the mystic art of Git
Git Is A State Of Mind - The path to becoming a Master of the mystic art of Git
 
Git tutorial
Git tutorial Git tutorial
Git tutorial
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Git 101 for Beginners
Git 101 for Beginners Git 101 for Beginners
Git 101 for Beginners
 
Git commands
Git commandsGit commands
Git commands
 
Git presentation
Git presentationGit presentation
Git presentation
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of trouble
 
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
What is Git | What is GitHub | Git Tutorial | GitHub Tutorial | Devops Tutori...
 

Similar to An introduction to Git

Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
Max Claus Nunes
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
Nguyen Van Hung
 
Git 101
Git 101Git 101
Git 101
Sachet Mittal
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
Roland Emmanuel Salunga
 
Git
Git Git
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
Kishor Kumar
 
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
 
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 GitRobert Lee-Cann
 
11 git version control
11 git version control11 git version control
11 git version control
Wasim Alatrash
 
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
WSO2
 
Git tips and tricks
Git   tips and tricksGit   tips and tricks
Git tips and tricks
Chris Ballance
 
Git Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptx
Eshaan35
 
Git and GitHub (1).pptx
Git and GitHub (1).pptxGit and GitHub (1).pptx
Git and GitHub (1).pptx
BetelAddisu
 
Learn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levelsLearn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levels
Gorav Singal
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
Prakash Dantuluri
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
Tilton2
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slide
RaghavendraVattikuti1
 
GIT In Detail
GIT In DetailGIT In Detail
GIT In Detail
Haitham Raik
 
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
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
Venkat Malladi
 

Similar to An introduction to Git (20)

Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
Introduction to git
Introduction to gitIntroduction to git
Introduction to git
 
Git 101
Git 101Git 101
Git 101
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git
Git Git
Git
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configuration
 
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
 
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
 
11 git version control
11 git version control11 git version control
11 git version control
 
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...Git workshop - University of Moratuwa, Department of Computer Science and Eng...
Git workshop - University of Moratuwa, Department of Computer Science and Eng...
 
Git tips and tricks
Git   tips and tricksGit   tips and tricks
Git tips and tricks
 
Git Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptx
 
Git and GitHub (1).pptx
Git and GitHub (1).pptxGit and GitHub (1).pptx
Git and GitHub (1).pptx
 
Learn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levelsLearn Git - For Beginners and Intermediate levels
Learn Git - For Beginners and Intermediate levels
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Git and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slideGit and Github workshop ppt slide by slide
Git and Github workshop ppt slide by slide
 
GIT In Detail
GIT In DetailGIT In Detail
GIT In Detail
 
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
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 

Recently uploaded

LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
Google
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
rickgrimesss22
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 

Recently uploaded (20)

LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
AI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website CreatorAI Genie Review: World’s First Open AI WordPress Website Creator
AI Genie Review: World’s First Open AI WordPress Website Creator
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptxTop Features to Include in Your Winzo Clone App for Business Growth (4).pptx
Top Features to Include in Your Winzo Clone App for Business Growth (4).pptx
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 

An introduction to Git

  • 2. What is GIT • Version control system • decentralised by nature but can be used as centralised by convention Repo Repo Repo
  • 3. Git Lifecycle • Create • Create a local repo or clone from existing • Create a remote repo for centralised sharing (also called bare repositories) • configure repository details, gitignore, remote repos • Collaborate • fetch,pull,commit,push changes • branching • merging vs rebasing • Maintain • iterate collaboration further sprints with tagging versions and releases • optimize
  • 5. Bare Repo vs Repo Bare repo Repo No working copy working copy checked out in the directory cannot edit directly edit commit and push changes usually used for centralised sharing for repositories used for development on local boxes git init --bare {directory name} git init {directory name}
  • 6. Remote Repository Services • Used to host Bare repositories • Main usage is as centralised repos for sharing • Can be an online service • Bitbucket, Github, AWS CodeCommit • Can be a local service • Gitlab
  • 7. Create a local repo • One time operation • To create a repository in current directory • git init • To create a repository in specified directory • git init {directory name} • This creates and checks out a empty repository to which files can be added. • a hidden directory called .git in the specified or working directory as applicable
  • 8. Add a remote repo • If the local repo is a new repo then we might need to add the remote repo setup for sharing • git remote add {remotename} {remote path/URL} • example • git remote add origin https://github.com/user/repo.git • we can have multiple remote repos to a local repo • change a remote URL • git remote set-url {remotename} {new remote url} • rename a remote • git remote rename {old name} {new name} • list all remotes • git remote -v
  • 9. Clone a repo • A repo can be cloned from a local machine or from a remote location to a specified location • the command structure is • git clone <repo path> <local directory name> • this can be done over ssh / https for remote repos and just by giving the path when cloning in the same machine. • if no local directory name is specified it clones into the current working directory as with the above examples • If need to clone to a specific directory , then need to specify the folder name at the end of the command • git clone https://github.com/username/repo.git /path/to/custom-directory-name
  • 10. Configuring a Git repo • The command structure usually is • git config <option> <parameter> <value> • the option can specify scope which can be local, global or system • local is for that repo, whereas global is for that user and system is system wide • git config --global user.email <email> • git config --global user.name <name> • local overrides global, global overrides system • local config is in .git/config • global is in ~/.gitconfig • system is in /etc/gitconfig
  • 11. Configuring a Git repo • We can do a variety of manipulations with git config command • some examples • Tell Git who you are • git config --global user.name "John Smith" • git config --global user.email john@example.com • Select your favourite text editor • git config --global core.editor vim • Ignore file permission changes for committing • git config --global core.fileMode false
  • 12. .gitignore • this is used to ignore any files/folder from the repository • a .gitignore file can have a rule ignoring a specific file or all files with an extension. • It can be used even to ignore itself (i don’t recommend it though) • example entries in the gitignore file • debug.log • *.log • img/* • !img/logo.png • Highly useful for ignoring user uploaded content from filling up the repo and keep the repo manageable
  • 14. Committing changes • We first need to stage any changes before committing. • this can be done for all files changed • git add . • for specific files by • git add {specific file name} • To commit the changes • git commit -m ‘message for commit’
  • 15. To track and update changes from/to remote • check status of current local repo • git status • to update tracking from remote repo • git fetch • to pull changes from remote repo • git pull {remote name} {branch name} • to push changes • git push {remote name} {branch name} • git push --all • git push --dry-run
  • 16. Amending, Reverting and Resetting a commit • To amend a commit • git commit --amend • reverting • when reverting it undoes a commit’s changes and creates a new commit • git revert <commit> • safer • resetting • resets your working copy to a particular commit undoing any other changes you have done • git reset [--soft --hard] <commit> • like in rebasing dangerous as public shared commits can get modified causing issues • to discard any working copy changes resetting this is useful • git reset --hard
  • 17. Committing a deleted file • Sometimes you need to delete a file from the repo • This doesn’t get automatically staged when you do git add . • Need to specify that you need to stage deleted files as well before committing • git add -u .
  • 18. Branching • A variety of strategies available • create branches for bugfixes, development of new features and any and all changes to codebase • create new branch • git branch {branch name} • git checkout {branch name} • these can be done with a single command as well • git checkout -b {branch name} • switch to an existing branch • git checkout {branch name} • list branches • git branch (for local only) • git branch -r (for remote only) • git branch -a (for both)
  • 19. Merging • The branches need to be merged to the master branch after testing for release. • to merge • switch to the branch that is to be merged into (ex) master • git checkout master • merge the branch (ex) hotfix1223 • git merge hotfix1223 • to merge Pull requests can also be used for an administrator to verify the changes in Remote repos • when merging we might run into conflicts
  • 20. Merge Conflicts • Do a git status to find which file is conflicting and open it • A conflicting file will look like the example on the side • A conflict occurs when there are changes from two branches on the same line • in the example the footer line has been changed on master and on the hot fix branch • All to more reason to NEVER do changes on the master branch directly • Also conflicts may occur when merging a branch from a different developer to your own branch <<<<<<< HEAD:index.html <div id="footer">contact : support@muhilvannan.com</div> ======= <div id="footer"> please contact us at support@muhilvannan.com </div> >>>>>>> hotfix1223:index.html
  • 21. Fixing Conflicts <<<<<<< HEAD:index.html to======= is the block on the master/ current branch ======= to >>>>>>> hotfix1223:index.html is the block on the branch to merged • these need to be replaced with the text as required. • the replacing text can be from the current branch or from the branch being merged or a combination of both • make sure <<<<<<< HEAD:index.html ======= >>>>>>> hotfix1223:index.html are removed fro the code as depicted in the right column • save and commit <<<<<<< HEAD:index.html <div id="footer">contact : support@muhilvannan.com</div> ======= <div id="footer"> please contact us at support@muhilvannan.com </div> >>>>>>> hotfix1223:index.html <div id="footer"> please contact us at support@muhilvannan.com </div> replace with
  • 22. Fixing Conflicts • There are graphical tools for fixing merge conflicts as well • git mergetool • you might need to configure the tool if not already • git config --global merge.tool {mergetool name} • kdiff3 and extmetge are very good tools
  • 23. Rebasing • Rebasing is the process of moving a branch to a new base commit • Useful to do locally • NOT SAFE for public history repositories, as the history might be modified and cause issues with other developers • The golden rule of git rebase is to never use it on public branches • I would recommend Merge instead of rebase just to eliminate this issue so as to never mistakenly change it
  • 25. Tagging • With git you can tag an commit for easy finding and downloading • also useful for tagging release versions • git tag -a {tag} -m ‘message' • git tag -a {tag} {commit number} • To checkout a branch and a tagged commit • git checkout -b [branchname] [tagname]
  • 26. Tagging • to list tags • git tag • push tags to remote • git push {remote name} --tags • delete a tag • git tag -d {tag} • git push {remote name} --tags
  • 27. Stashing • Files not ready to be committed can be stashed. • git stash • git stash list • git stash apply
  • 28. Optimize a Git repo • used to optimise git repo and clean up loose objects • sometimes run along with usual git commands • can also be run manually • 'git gc' [--aggressive] [--auto] [--quiet] [--prune=<date> | --no-prune] [—force]
  • 29. GUI tools for git • Sourcetree - mac & windows • Tower - mac • GitEye - linux • Github for windows • Github for mac
  • 30. Things to note • Git doesn’t maintain a folder structure if nothing underneath it is gitted. • files called empty should be added to the folder and the repo for this purpose • File permissions are usually gitted along with the files and if you want to ignore any changes to file permissions the repo needs to be configured
  • 31. Useful Documentation Links • https://help.github.com/articles/good-resources-for-learning-git-and- github/ • https://www.atlassian.com/git/tutorials/setting-up-a-repository • http://git-scm.com/doc • https://git-scm.com/downloads/guis