SlideShare a Scribd company logo
1 of 31
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 IJim Yeh
 
Git tutorial
Git tutorialGit tutorial
Git tutorialmobaires
 
Git - Basic Crash Course
Git - Basic Crash CourseGit - Basic Crash Course
Git - Basic Crash CourseNilay Binjola
 
Git walkthrough
Git walkthroughGit walkthrough
Git walkthroughBimal Jain
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of GitDivineOmega
 
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 GitNicola Costantino
 
Gitting out of trouble
Gitting out of troubleGitting out of trouble
Gitting out of troubleJon 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
 
Git installation and configuration
Git installation and configurationGit installation and configuration
Git installation and configurationKishor 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 GitGeoff 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 controlWasim 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 Session 2K23.pptx
Git Session 2K23.pptxGit Session 2K23.pptx
Git Session 2K23.pptxEshaan35
 
Git and GitHub (1).pptx
Git and GitHub (1).pptxGit and GitHub (1).pptx
Git and GitHub (1).pptxBetelAddisu
 
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 levelsGorav Singal
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdfTilton2
 
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 slideRaghavendraVattikuti1
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Ahmed El-Arabawy
 

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
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
Embedded Systems: Lecture 12: Introduction to Git & GitHub (Part 3)
 

Recently uploaded

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 

Recently uploaded (20)

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 

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