SlideShare a Scribd company logo
Introduction to Git
Adarsh Konchady
Git v/s other VCS?
• Git is decentralized
• Nearly every operation is local.
• Git thinks differently about its data.
• Branching is simplified
Git workflow
Committed
region
(snapshots)
Staging area
Working
directory
Commit
Add
Central repository
Push
Local to each user
git init
• Create a new repository
• Usage:
o git init
• Initialize a repo with .git
o git init <directory>
• Creates a empty git repo
git config
• git config --global user.name <firstName lastName>
• git config --global user.email <email>
• git config --global credential.helper wincred
o Cache password
• Config paths:
o <repo>/.git/config – Repository-specific settings.
o ~/.gitconfig – User-specific settings. This is where options set with
the --global flag are stored.
o $(prefix)/etc/gitconfig – System-wide settings.
git status
• Status of the working directory and staging area
• Usage: git status
git add
• Add a untracked/modifed file to staging area
• git add <file>
git commit
• Put the staged snapshot into the committed
history
• git commit -m “commit message”
• git comit --amend
o Combine the staged changes with the previous commit and replace
the previous commit with the resulting snapshot.
git push
• Usage
o git push
• git push --set-upstream origin <branch>
o Pushes commits to <branch>
• Push a specific commit
o git push <remotename> <commit SHA>:<remotebranchname>
o Note that this pushes all commits up to and including the commit you
choose. If you don't want that to happen, you should first use ’git
rebase –I’ to re-order the commits.
• While pushing a new repo, 2 extra steps:
o git remote add origin <repo_url>
o git push --set-upstream origin master
git checkout
• git checkout <commit> <file>
• Checkout files
• git checkout <commit>
• Checkout commits
• git checkout <branch>
• Checkout branch
git log
• git log
o Log of the committed history
• git log –oneline
• git log origin/master..master
o Check only unpushed commits
Undo changes
• git reset
o – Undoes changes from staging area to match most recent commit
• git reset –hard
o Reset the staging area and the working directory to match the most
recent commit.
• git reset <commit>
o Move the current branch tip backward to <commit>, reset the staging
area to match, but leave the working directory alone.
• git revert <commit>
o Generate a new commit that undoes all of the changes introduced in
<commit>, then apply it to the current branch.
• git clean
o Removes untracked files from working directory.
Rewriting history
• git commit –amend
o Combine the staged changes with the previous commit and replace
the previous commit with the resulting snapshot.
• git rebase <base>
o Rebase the current branch onto <base>, which can be any kind of
commit reference (an ID, a branch name, a tag, or a relative
reference to HEAD).
Branching
• git branch
o Create a new branch
• git checkout –b <branch>
o Create a new branch and switch into it
• git branch --merged
o Show only merged branches
• git branch --no-merged
o Show only unmerged branches
• git branch -d <branch>
o Delete a branch
• git branch -D <branch>
o Force delete a branch even if it has not been merged yet
Modifying files in a
pushed commit
• http://stackoverflow.com/a/28173964/802651
• Steps :
• git checkout <commit_id> <path_to_file>
• Modify the files that you want to undo/change
• git commit -am "remove unwanted files“
• Find commitId where files were added mistakenly
• git rebase 35c23c2~1 -i // notice: "~1" is necessary
• pick 35c23c2 the first commit
• fixup 0d78b28 remove unwanted files
• If you unfortunately get conflicts, resolve them
manually.

More Related Content

PPT
Apresentação Service Desk
DOCX
05. Physical Data Specification Template
PPTX
Executive Status Report Template
PDF
Gathering Business Requirements for Data Warehouses
PPTX
Budgeting
PPTX
Managing Service Operations and why ITSM Matters
PDF
Data Driven Culture with Slalom's Director of Analytics
PDF
Dataverse opportunities
 
Apresentação Service Desk
05. Physical Data Specification Template
Executive Status Report Template
Gathering Business Requirements for Data Warehouses
Budgeting
Managing Service Operations and why ITSM Matters
Data Driven Culture with Slalom's Director of Analytics
Dataverse opportunities
 

What's hot (6)

PPTX
Project integration management
PDF
Project Management Concepts (from PMBOK 5th Ed)
PDF
Lessons from building a stream-first metadata platform | Shirshanka Das, Stealth
DOCX
07. Analytics & Reporting Requirements Template
PPTX
7.3 Determine Budget
PDF
Project Management Kickoff Meeting Template Powerpoint Presentation Slides
Project integration management
Project Management Concepts (from PMBOK 5th Ed)
Lessons from building a stream-first metadata platform | Shirshanka Das, Stealth
07. Analytics & Reporting Requirements Template
7.3 Determine Budget
Project Management Kickoff Meeting Template Powerpoint Presentation Slides
Ad

Similar to Git basic commands (20)

PPTX
Techoalien git
PPTX
Techoalien git
PPTX
Techoalien git
PPTX
Git session Dropsolid.com
PPTX
Git and git workflow best practice
PPTX
Working with Git
PDF
Git with the flow
PDF
Git tutorial
PPTX
Git walkthrough
PPTX
Git-ing out of your git messes
PDF
Advanced Git
PPTX
Git tutorial
PDF
Advanced Git - Functionality and Features
PDF
Git and github 101
PPTX
Introduction into Git
PPTX
An introduction to Git
PPTX
GIT.pptx
KEY
Use git the proper way
PDF
Git_real_slides
Techoalien git
Techoalien git
Techoalien git
Git session Dropsolid.com
Git and git workflow best practice
Working with Git
Git with the flow
Git tutorial
Git walkthrough
Git-ing out of your git messes
Advanced Git
Git tutorial
Advanced Git - Functionality and Features
Git and github 101
Introduction into Git
An introduction to Git
GIT.pptx
Use git the proper way
Git_real_slides
Ad

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Electronic commerce courselecture one. Pdf
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Big Data Technologies - Introduction.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
Building Integrated photovoltaic BIPV_UPV.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The AUB Centre for AI in Media Proposal.docx
Spectral efficient network and resource selection model in 5G networks
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
Understanding_Digital_Forensics_Presentation.pptx
20250228 LYD VKU AI Blended-Learning.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Electronic commerce courselecture one. Pdf
Machine learning based COVID-19 study performance prediction
Spectroscopy.pptx food analysis technology
Big Data Technologies - Introduction.pptx
sap open course for s4hana steps from ECC to s4
MIND Revenue Release Quarter 2 2025 Press Release
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

Git basic commands

  • 2. Git v/s other VCS? • Git is decentralized • Nearly every operation is local. • Git thinks differently about its data. • Branching is simplified
  • 4. git init • Create a new repository • Usage: o git init • Initialize a repo with .git o git init <directory> • Creates a empty git repo
  • 5. git config • git config --global user.name <firstName lastName> • git config --global user.email <email> • git config --global credential.helper wincred o Cache password • Config paths: o <repo>/.git/config – Repository-specific settings. o ~/.gitconfig – User-specific settings. This is where options set with the --global flag are stored. o $(prefix)/etc/gitconfig – System-wide settings.
  • 6. git status • Status of the working directory and staging area • Usage: git status
  • 7. git add • Add a untracked/modifed file to staging area • git add <file>
  • 8. git commit • Put the staged snapshot into the committed history • git commit -m “commit message” • git comit --amend o Combine the staged changes with the previous commit and replace the previous commit with the resulting snapshot.
  • 9. git push • Usage o git push • git push --set-upstream origin <branch> o Pushes commits to <branch> • Push a specific commit o git push <remotename> <commit SHA>:<remotebranchname> o Note that this pushes all commits up to and including the commit you choose. If you don't want that to happen, you should first use ’git rebase –I’ to re-order the commits. • While pushing a new repo, 2 extra steps: o git remote add origin <repo_url> o git push --set-upstream origin master
  • 10. git checkout • git checkout <commit> <file> • Checkout files • git checkout <commit> • Checkout commits • git checkout <branch> • Checkout branch
  • 11. git log • git log o Log of the committed history • git log –oneline • git log origin/master..master o Check only unpushed commits
  • 12. Undo changes • git reset o – Undoes changes from staging area to match most recent commit • git reset –hard o Reset the staging area and the working directory to match the most recent commit. • git reset <commit> o Move the current branch tip backward to <commit>, reset the staging area to match, but leave the working directory alone. • git revert <commit> o Generate a new commit that undoes all of the changes introduced in <commit>, then apply it to the current branch. • git clean o Removes untracked files from working directory.
  • 13. Rewriting history • git commit –amend o Combine the staged changes with the previous commit and replace the previous commit with the resulting snapshot. • git rebase <base> o Rebase the current branch onto <base>, which can be any kind of commit reference (an ID, a branch name, a tag, or a relative reference to HEAD).
  • 14. Branching • git branch o Create a new branch • git checkout –b <branch> o Create a new branch and switch into it • git branch --merged o Show only merged branches • git branch --no-merged o Show only unmerged branches • git branch -d <branch> o Delete a branch • git branch -D <branch> o Force delete a branch even if it has not been merged yet
  • 15. Modifying files in a pushed commit • http://stackoverflow.com/a/28173964/802651 • Steps : • git checkout <commit_id> <path_to_file> • Modify the files that you want to undo/change • git commit -am "remove unwanted files“ • Find commitId where files were added mistakenly • git rebase 35c23c2~1 -i // notice: "~1" is necessary • pick 35c23c2 the first commit • fixup 0d78b28 remove unwanted files • If you unfortunately get conflicts, resolve them manually.

Editor's Notes

  • #13: git reset <commit> Move the current branch tip backward to <commit>, reset the staging area to match, but leave the working directory alone. All changes made since <commit> will reside in the working directory, which lets you re-commit the project history using cleaner, more atomic snapshots. git reset --hard <commit> Move the current branch tip backward to <commit> and reset both the staging area and the working directory to match. This obliterates not only the uncommitted changes, but all commits after <commit>, as well.