SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
git for beginners
Arulmurugan
@arulmrr
www.indjango.com
git
● Source code management software
● DVCS (Distributed Version Control System)
● hg - Similar tool
● CVS, Bazaar, SVN
Installation
● Ubuntu
sudo apt-get install git
● Windows
Ubuntu and Windows
● Commands here can be executed in the
respective OS as defined below
● Ubuntu
○ Can use their system terminal
● Windows
○ Select git bash in your Right-click context menu
git Hosting
Bitbucket Github
Unlimited public and private repositories Unlimited Public repositories
Cost based on number of users Cost based on number of repositories
Supports git and hg Supports git only
● Codeplane, Githost, Assembla, Cloudforge, Gitorious
● Bitbucket
Username - arulmurugan
E-Mail - arulmurugan@example.com
ssh-key Setup
● ssh-keygen #Command to generate public key
● Copy contents of id_rsa.pub
Bitbucket - Create Repo
An empty repo
Repo - User Management
● To manage who access your repository
Git configuration
Basic Configurations:
● git config --global user.name "second_user_name"
● git config --global user.email "second_user_email"
● git config --global push.default "matching"
● git config --global color.status auto
● git config --global color.branch auto
● git config --list
Optional Configurations:
● git config --global branch.master.remote origin
● git config --global branch.master.merge refs/heads/master
.gitignore
● Can be configured to ignore certain files and
directories
● Git ignores empty directories by default
My first repo
● cd ~/git/myproject/
#Open your project directory in terminal
● git init
#Initiating a git repository
● git remote add origin git@bitbucket.org:arulmurugan/dummy.git
#Adding remote repository URL
● git add .
#Adding files to be committed
● git commit -m "Initial commit"
#Committing the added files and changes
● git push origin master
#Pushing the commits to remote repository
Repo with Initial commit
git status
● Will show the list changed and new files
which are yet to be committed
git add & git commit
● git add .
#To add all untracked files
● git add test2.html
#To add specific files
● git commit -am "commit message"
#To commit all changed files
● git commit -m "commit message" test1.html
#To commit specific files
git add & git commit (Contd...)
Bitbucket - Source and Commits
git pull
● To pull changes pushed by other users from
remote repo to local repo
Merge conflicts
● A merge conflicts occurs, if two people have
modified the same content.
git mergetool
● http://meldmerge.org/
Status and History
● git diff
#Shows differences in uncommitted files / last commit
● git log
#Shows history of commits in the current branch
● git log --oneline --abbrev-commit
#Shows one line commit history with short commit id
● git log --graph --pretty --oneline --abbrev-commit
#Shows the history as graph
● git diff-tree --name-only -r <commit_id>
#Shows files changed in the commit
● git show <commit_id>
#Shows changes in the commit
History of file
● git log [filename]
#Shows commits for the file
● git log -p [filename]
#Shows commits for the file with changes
● git log --follow -p [filename]
#Shows commits for the file including renames
● git blame [filename]
#Shows author and commit per line of the file
● git blame -L 1,3 [filename]
#Shows author and commit from line 2 to line 3
● git commit --amend -m "More changes - now correct"
#To amend changes to previous commit before pushing
Remote repositories
● git remote
#Show the existing remote repos
● git remote show origin
#Show the details of remote repo origin
● git clone git@bitbucket.org:arulmurugan/dummy.git
#To clone remote repository
git stash
● Allows to save the current uncommitted
changes and checkout the last committed
revision.
● Allows you to pull in the latest changes
without conflicts.
● Afterwards you can restore the stashed
changes, which will apply the changes to the
current version of the source code.
git stash (Contd...)
● git stash save "stash message"
#To save uncommited changes as stash
● git stash list
#To view list of saved stashes
#stash@{0}: On master: Title changed
● git stash apply stash@{0}
#To apply the particular stash
● git stash drop stash@{0}
#To drop particular stash
● git stash clear
#To drop all saved stashes
● git stash pop
#To apply most recent stash and delete it from list of stashes
git stash (Contd...)
Reverting changes
● git clean - To remove newly added files
○ git clean -n
#To see what would happen
○ git clean -f
#To remove the files
● git checkout - To revert changed and deleted files
○ git checkout .
#To revert all changed files
○ git checkout [filename]
#To restore or revert the file
○ git checkout <commit_id>
#To checkout a particular commit
Reverting changes (Contd...)
● git reset [filename]
#To remove a file added by git add before pushing
● git checkout HEAD -- [dir_name]
#To recover an accidentally deleted directory in repo
● git revert <commit_id>
#To revert a particular commit
● git reset --hard HEAD~1
#To delete last 1 commit
● git reset --hard <sha1-commit-id>
#To delete upto a particular commit
● git push -f
#Push with force to push commit deletions
Reverting changes (Contd...)
● git reflog
#Shows a history of the complete changes of your
current branch based on the HEAD revision
● git reset --hard <commit_id>
#To revert to a commit shown in git reflog
Branches
● Branches are copies of the files from a certain
commit and they can be changed independently
from each other.
● The default branch is called master.
● Untracked files remain unchanged and are
available in the new branch. This allows you to
create a branch for unstaged and uncommitted
changes at any point in time.
Branches (Contd...)
● git branch
#List available branches
● git branch -a
#List available branches including remote branches
● git branch -r
#List remote branches only
● git branch <branch_name>
#To create new branch
● git checkout <branch_name>
#To switch to a branch
● git checkout -b <branch_name>
#To create a branch and switch to it
Branches (Contd...)
● git checkout -b <branch_name> master~1
#Create a new branch based on master without last commit
● git branch -d <branch_name>
#To delete a branch
● git push origin <branch_name>
#To push branch to remote
● git push origin --delete <branch_name>
#To delete a remote branch
● git checkout -b <branch_name> origin/<branch_name>
#To create a tracking branch
● git merge <branch_name>
#To merge specified branch with current branch
Retrieving files
● git show [reference]:[filename]
#To see contents of a file
# [reference] can be a branch, tag, HEAD or commit ID
● git show [reference]:[filename] > [filename_copy]
#To copy a file
● git log -- [filename]
#To see commit history of a file, even if deleted
Alias
● Allows you to setup your own git command
● git config --global alias.st 'git status'
#Set command "st" for git status
#Now git st can be used instead of git status
● git config --global alias.acm '!git add . -A && git commit'
#Set command "acm" for git add . and git commit
#Now you can use git acm "message" for commits
#Not supported in windows*
Submodules - Repos inside repos
● Allows you to include another Git repository
into a Git repository
● git submodule add [URL to Git repo]
#To add submodule to your repo
● After cloning a repo with submodules
○ git submodule init
#Creates local configuration file for submodules
○ git submodule update
#To clone submodules
● Rebase
● Patches
● Git server
Missed Out:
References:
1. http://www.vogella.com/articles/Git/article.html
2. http://git-scm.com/book/
3. http://www.kernel.org/pub/software/scm/git/docs/
Thank you
arul@indjango.com

Mais conteúdo relacionado

Mais procurados

Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to gitEmanuele Olivetti
 
Introduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training SessionIntroduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training SessionAnwarul Islam
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and GithubHouari ZEGAI
 
Version Control History and Git Basics
Version Control History and Git BasicsVersion Control History and Git Basics
Version Control History and Git BasicsSreedath N S
 
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 overviewRueful Robin
 

Mais procurados (20)

Introduction git
Introduction gitIntroduction git
Introduction git
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Git basic
Git basicGit basic
Git basic
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Git basics
Git basicsGit basics
Git basics
 
Git
GitGit
Git
 
Introduction To Git
Introduction To GitIntroduction To Git
Introduction To Git
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
A Practical Introduction to git
A Practical Introduction to gitA Practical Introduction to git
A Practical Introduction to git
 
Introduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training SessionIntroduction to Gitlab | Gitlab 101 | Training Session
Introduction to Gitlab | Gitlab 101 | Training Session
 
Git n git hub
Git n git hubGit n git hub
Git n git hub
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Version Control History and Git Basics
Version Control History and Git BasicsVersion Control History and Git Basics
Version Control History and Git Basics
 
git and github
git and githubgit and github
git and github
 
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overviewGit and GitHub | Concept about Git and GitHub Process | Git Process overview
Git and GitHub | Concept about Git and GitHub Process | Git Process overview
 
Git and git flow
Git and git flowGit and git flow
Git and git flow
 

Destaque

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
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to gitJoel Krebs
 
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
 
How to become a Git power user
How to become a Git power userHow to become a Git power user
How to become a Git power userDeveo
 
Git in pills : git stash
Git in pills : git stashGit in pills : git stash
Git in pills : git stashFederico Panini
 
Git & e git beginner workshop
Git & e git beginner workshopGit & e git beginner workshop
Git & e git beginner workshopIgor Laborie
 
Git 101 tutorial presentation
Git 101 tutorial presentationGit 101 tutorial presentation
Git 101 tutorial presentationTerry Wang
 
Introduction to Continuous Integration with Jenkins
Introduction to Continuous Integration with JenkinsIntroduction to Continuous Integration with Jenkins
Introduction to Continuous Integration with JenkinsEric Hogue
 
Ci jenkins maven svn
Ci jenkins maven svnCi jenkins maven svn
Ci jenkins maven svnAnkur Goyal
 
Gastrointestinal mcq
Gastrointestinal mcqGastrointestinal mcq
Gastrointestinal mcqRashed Hassen
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programmingMukesh Tekwani
 
System Programming Unit III
System Programming Unit IIISystem Programming Unit III
System Programming Unit IIIManoj Patil
 

Destaque (20)

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
 
Quick Introduction to git
Quick Introduction to gitQuick Introduction to git
Quick Introduction to git
 
Git tutorial
Git tutorial Git tutorial
Git tutorial
 
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
 
How to become a Git power user
How to become a Git power userHow to become a Git power user
How to become a Git power user
 
Git in pills : git stash
Git in pills : git stashGit in pills : git stash
Git in pills : git stash
 
Git & e git beginner workshop
Git & e git beginner workshopGit & e git beginner workshop
Git & e git beginner workshop
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git for the absolute beginners
Git for the absolute beginnersGit for the absolute beginners
Git for the absolute beginners
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
 
Git 101 tutorial presentation
Git 101 tutorial presentationGit 101 tutorial presentation
Git 101 tutorial presentation
 
Django in Eclipse
Django in EclipseDjango in Eclipse
Django in Eclipse
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git essentials
Git essentialsGit essentials
Git essentials
 
Introduction to Continuous Integration with Jenkins
Introduction to Continuous Integration with JenkinsIntroduction to Continuous Integration with Jenkins
Introduction to Continuous Integration with Jenkins
 
Ci jenkins maven svn
Ci jenkins maven svnCi jenkins maven svn
Ci jenkins maven svn
 
Git physiology ga
Git physiology  gaGit physiology  ga
Git physiology ga
 
Gastrointestinal mcq
Gastrointestinal mcqGastrointestinal mcq
Gastrointestinal mcq
 
Introduction to systems programming
Introduction to systems programmingIntroduction to systems programming
Introduction to systems programming
 
System Programming Unit III
System Programming Unit IIISystem Programming Unit III
System Programming Unit III
 

Semelhante a Git for beginners

Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptuallyseungzzang Kim
 
Essential Git and Github commands
Essential Git and Github commandsEssential Git and Github commands
Essential Git and Github commandsIsham Rashik
 
GIT_GITHUB_2016_06_17
GIT_GITHUB_2016_06_17GIT_GITHUB_2016_06_17
GIT_GITHUB_2016_06_17siva ram
 
Git tech talk
Git tech talkGit tech talk
Git tech talkrazasayed
 
Getting some Git
Getting some GitGetting some Git
Getting some GitBADR
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practiceMajid Hosseini
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Git Intermediate Course
Git Intermediate CourseGit Intermediate Course
Git Intermediate CourseAli Abbasi
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commandsZakaria Bouazza
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubDSC GVP
 
How to git easily in day to-day work
How to git easily in day to-day workHow to git easily in day to-day work
How to git easily in day to-day workAlena Radkevich
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践Terry Wang
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践Terry Wang
 

Semelhante a Git for beginners (20)

Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Essential Git and Github commands
Essential Git and Github commandsEssential Git and Github commands
Essential Git and Github commands
 
GIT_GITHUB_2016_06_17
GIT_GITHUB_2016_06_17GIT_GITHUB_2016_06_17
GIT_GITHUB_2016_06_17
 
Git tech talk
Git tech talkGit tech talk
Git tech talk
 
Git cheat-sheet 2021
Git cheat-sheet 2021Git cheat-sheet 2021
Git cheat-sheet 2021
 
Git cheat-sheet
Git cheat-sheetGit cheat-sheet
Git cheat-sheet
 
Getting some Git
Getting some GitGetting some Git
Getting some Git
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Git Intermediate Course
Git Intermediate CourseGit Intermediate Course
Git Intermediate Course
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
 
Introduction to GIT
Introduction to GITIntroduction to GIT
Introduction to GIT
 
Git commands
Git commandsGit commands
Git commands
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
How to git easily in day to-day work
How to git easily in day to-day workHow to git easily in day to-day work
How to git easily in day to-day work
 
Git commands
Git commandsGit commands
Git commands
 
Git
GitGit
Git
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 

Último

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Git for beginners

  • 2. git ● Source code management software ● DVCS (Distributed Version Control System) ● hg - Similar tool ● CVS, Bazaar, SVN
  • 3. Installation ● Ubuntu sudo apt-get install git ● Windows
  • 4. Ubuntu and Windows ● Commands here can be executed in the respective OS as defined below ● Ubuntu ○ Can use their system terminal ● Windows ○ Select git bash in your Right-click context menu
  • 5. git Hosting Bitbucket Github Unlimited public and private repositories Unlimited Public repositories Cost based on number of users Cost based on number of repositories Supports git and hg Supports git only ● Codeplane, Githost, Assembla, Cloudforge, Gitorious ● Bitbucket Username - arulmurugan E-Mail - arulmurugan@example.com
  • 6. ssh-key Setup ● ssh-keygen #Command to generate public key ● Copy contents of id_rsa.pub
  • 9. Repo - User Management ● To manage who access your repository
  • 10. Git configuration Basic Configurations: ● git config --global user.name "second_user_name" ● git config --global user.email "second_user_email" ● git config --global push.default "matching" ● git config --global color.status auto ● git config --global color.branch auto ● git config --list Optional Configurations: ● git config --global branch.master.remote origin ● git config --global branch.master.merge refs/heads/master
  • 11. .gitignore ● Can be configured to ignore certain files and directories ● Git ignores empty directories by default
  • 12. My first repo ● cd ~/git/myproject/ #Open your project directory in terminal ● git init #Initiating a git repository ● git remote add origin git@bitbucket.org:arulmurugan/dummy.git #Adding remote repository URL ● git add . #Adding files to be committed ● git commit -m "Initial commit" #Committing the added files and changes ● git push origin master #Pushing the commits to remote repository
  • 14. git status ● Will show the list changed and new files which are yet to be committed
  • 15. git add & git commit ● git add . #To add all untracked files ● git add test2.html #To add specific files ● git commit -am "commit message" #To commit all changed files ● git commit -m "commit message" test1.html #To commit specific files
  • 16. git add & git commit (Contd...)
  • 17. Bitbucket - Source and Commits
  • 18. git pull ● To pull changes pushed by other users from remote repo to local repo
  • 19. Merge conflicts ● A merge conflicts occurs, if two people have modified the same content.
  • 21. Status and History ● git diff #Shows differences in uncommitted files / last commit ● git log #Shows history of commits in the current branch ● git log --oneline --abbrev-commit #Shows one line commit history with short commit id ● git log --graph --pretty --oneline --abbrev-commit #Shows the history as graph ● git diff-tree --name-only -r <commit_id> #Shows files changed in the commit ● git show <commit_id> #Shows changes in the commit
  • 22. History of file ● git log [filename] #Shows commits for the file ● git log -p [filename] #Shows commits for the file with changes ● git log --follow -p [filename] #Shows commits for the file including renames ● git blame [filename] #Shows author and commit per line of the file ● git blame -L 1,3 [filename] #Shows author and commit from line 2 to line 3 ● git commit --amend -m "More changes - now correct" #To amend changes to previous commit before pushing
  • 23. Remote repositories ● git remote #Show the existing remote repos ● git remote show origin #Show the details of remote repo origin ● git clone git@bitbucket.org:arulmurugan/dummy.git #To clone remote repository
  • 24. git stash ● Allows to save the current uncommitted changes and checkout the last committed revision. ● Allows you to pull in the latest changes without conflicts. ● Afterwards you can restore the stashed changes, which will apply the changes to the current version of the source code.
  • 25. git stash (Contd...) ● git stash save "stash message" #To save uncommited changes as stash ● git stash list #To view list of saved stashes #stash@{0}: On master: Title changed ● git stash apply stash@{0} #To apply the particular stash ● git stash drop stash@{0} #To drop particular stash ● git stash clear #To drop all saved stashes ● git stash pop #To apply most recent stash and delete it from list of stashes
  • 27. Reverting changes ● git clean - To remove newly added files ○ git clean -n #To see what would happen ○ git clean -f #To remove the files ● git checkout - To revert changed and deleted files ○ git checkout . #To revert all changed files ○ git checkout [filename] #To restore or revert the file ○ git checkout <commit_id> #To checkout a particular commit
  • 28. Reverting changes (Contd...) ● git reset [filename] #To remove a file added by git add before pushing ● git checkout HEAD -- [dir_name] #To recover an accidentally deleted directory in repo ● git revert <commit_id> #To revert a particular commit ● git reset --hard HEAD~1 #To delete last 1 commit ● git reset --hard <sha1-commit-id> #To delete upto a particular commit ● git push -f #Push with force to push commit deletions
  • 29. Reverting changes (Contd...) ● git reflog #Shows a history of the complete changes of your current branch based on the HEAD revision ● git reset --hard <commit_id> #To revert to a commit shown in git reflog
  • 30. Branches ● Branches are copies of the files from a certain commit and they can be changed independently from each other. ● The default branch is called master. ● Untracked files remain unchanged and are available in the new branch. This allows you to create a branch for unstaged and uncommitted changes at any point in time.
  • 31. Branches (Contd...) ● git branch #List available branches ● git branch -a #List available branches including remote branches ● git branch -r #List remote branches only ● git branch <branch_name> #To create new branch ● git checkout <branch_name> #To switch to a branch ● git checkout -b <branch_name> #To create a branch and switch to it
  • 32. Branches (Contd...) ● git checkout -b <branch_name> master~1 #Create a new branch based on master without last commit ● git branch -d <branch_name> #To delete a branch ● git push origin <branch_name> #To push branch to remote ● git push origin --delete <branch_name> #To delete a remote branch ● git checkout -b <branch_name> origin/<branch_name> #To create a tracking branch ● git merge <branch_name> #To merge specified branch with current branch
  • 33. Retrieving files ● git show [reference]:[filename] #To see contents of a file # [reference] can be a branch, tag, HEAD or commit ID ● git show [reference]:[filename] > [filename_copy] #To copy a file ● git log -- [filename] #To see commit history of a file, even if deleted
  • 34. Alias ● Allows you to setup your own git command ● git config --global alias.st 'git status' #Set command "st" for git status #Now git st can be used instead of git status ● git config --global alias.acm '!git add . -A && git commit' #Set command "acm" for git add . and git commit #Now you can use git acm "message" for commits #Not supported in windows*
  • 35. Submodules - Repos inside repos ● Allows you to include another Git repository into a Git repository ● git submodule add [URL to Git repo] #To add submodule to your repo ● After cloning a repo with submodules ○ git submodule init #Creates local configuration file for submodules ○ git submodule update #To clone submodules
  • 36. ● Rebase ● Patches ● Git server Missed Out: