SlideShare une entreprise Scribd logo
1  sur  38
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An IntroductionBehzad Altaf
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHubNicolás Tourné
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notesglen_a_smith
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsLee Hanxue
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdfTilton2
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagramsDilum Navanjana
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git TutorialSage Sharp
 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticlePRIYATHAMDARISI
 

Tendances (20)

Git - An Introduction
Git - An IntroductionGit - An Introduction
Git - An Introduction
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
Git One Day Training Notes
Git One Day Training NotesGit One Day Training Notes
Git One Day Training Notes
 
Github - Git Training Slides: Foundations
Github - Git Training Slides: FoundationsGithub - Git Training Slides: Foundations
Github - Git Training Slides: Foundations
 
Basic Git Intro
Basic Git IntroBasic Git Intro
Basic Git Intro
 
Git real slides
Git real slidesGit real slides
Git real slides
 
Git basics
Git basicsGit basics
Git basics
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
 
Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
 
Git training v10
Git training v10Git training v10
Git training v10
 
git and github
git and githubgit and github
git and github
 
Git
GitGit
Git
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git n git hub
Git n git hubGit n git hub
Git n git hub
 
Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
GitHub Basics - Derek Bable
GitHub Basics - Derek BableGitHub Basics - Derek Bable
GitHub Basics - Derek Bable
 
Introduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech ArticleIntroduction to GitHub, Open Source and Tech Article
Introduction to GitHub, Open Source and Tech Article
 

En vedette

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
 

En vedette (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
 

Similaire à 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
 
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
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of GitDivineOmega
 

Similaire à 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
 
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 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Git
GitGit
Git
 
Git 入门 与 实践
Git 入门 与 实践Git 入门 与 实践
Git 入门 与 实践
 
The Fundamentals of Git
The Fundamentals of GitThe Fundamentals of Git
The Fundamentals of Git
 

Dernier

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
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
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
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
 
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
 
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
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 

Dernier (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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...
 
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
 
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
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
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
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 

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: