SlideShare una empresa de Scribd logo
1 de 10
git Most Used Commands
GIT Commands
Commands Description
git --version To check version of Git installed.
git config--system user.name <username> System level (All users on the system)
git config --global user.name <username> Global level (for all the projects of a user)
git config --local user.name <username> Local (default and specific for a repository)
git config --global core.excludesfile
%USERPROFILE%.gitignore
. gitignore files should have the list of files to be
ignored.
git add . To add new and modified but not deleted.
git add -u To add modified and deleted but not new
files/directories
GIT Commands
Commands Description
git Add -u To add modified and deleted and new
files/directories.
git commit --am “<message to commit> Creates a commit and adds files to staging.
git commit --m “<message to commit> Creates a commit from staging. Assumes files already
added to staging
git init Creates .git subfolder in the project, which contains all
necessary metadata
git remote add origin
https://github.com/Viyaan/<repository>.git
To add a new repo
git push origin <source_branch>:<destination branch> Actual syntax but the below syntax is enough
git push -u origin <source branch name> push your changes to selected branch, since source
and destination will always be same. It’s enough to
mention only source branch.
GIT Commands
Commands Description
git status gives status of tracked and untracked changes in your
local repository.
git branch list all available branches in local system.
git branch -r list all branches in repository
git branch <new branch name> create a new branch
git checkout <branch name> switch to another branch
git checkout -b <branch name> creates and switches to another branch
git merge <branch name> Merges specified branch into current.
GIT Commands
Commands Description
git rm <file name> To delete a file, you must commit and push after
deleting.
git diff <file-name> To see difference between uncommitted version to
remote version of a file.
git diff shows the changes you have done in your existing file
(compare different versions of your files)
git log Prints log of past commits
git log --oneline Prints log of past commits in one line.
git tag list all tags.
git tag <tag name> create a tag. You need to push after new tag is
created.
GIT Commands
Commands Description
git branch -D <branch name> To delete a branch. You must push after delete
command.
git branch -d <branch name> Same as above but this time it will ask for
confirmation If its not merged.
git push origin :<destination branch> After deleting you must push and while pushing you
should mention the destination branch. Destination
branch is the branch u deleted.
git tag -d <tag name> To delete a tag, use small d and not capital.
git clone <clone url> To clone a repository
git fetch origin To fetch new data from remote repository. But it
doesn’t integrate any of those new data into your
working files.
GIT Commands
Commands Description
git pull pull not only downloads new data; it also
directly integrates it into your current working copy
files.
git remote add <remote-name> <remote-url> To add a new remote, use the git remote
add command on the terminal, in the directory your
repository is stored at.
git remote show To see number of remote repositories available.
git stash Git stash temporarily shelves or stashes changes made
to your working copy so you can work on something
else, and come back and re-apply them later.
git stash save <stash name> To save list of uncommitted changes in stash.
git stash list List of stashes.
git stash pop Apply changes which were stashed.
GIT Commands
Commands Description
git commit --amend Modify the most recent commit
git commit --amend -m "an updated commit message" Modify the most recent commit message
git rev -parse HEAD Specify where head pointing too.
Reset
• git reset --soft <commit id>
• git reset --mixed <commit id>
• The difference between --mixed and --soft is whether or not your index is also modified. So, if we're on branch master
with this series of commits:
• - A - B - C (master)
• HEADpoints to C and the index matches C.
• When we run git reset --soft B, master (and thus HEAD) now points to B, but the index still has the changes from C; git
status will show them as staged. So if we run git commit at this point, we'll get a new commit with the same changes as C.
• ________________________________________
• Okay, so starting from here again:
• - A - B - C (master)
• Now let's do git reset --mixed B. (Note: --mixed is the default option). Once again, master and HEAD point to B, but this
time the index is also modified to match B. If we run git commit at this point, nothing will happen since the index matches
HEAD. We still have the changes in the working directory, but since they're not in the index, git status shows them as
unstaged. To commit them, you would git add and then commit as usual.
• ________________________________________
• And finally, --hard is the same as --mixed (it changes your HEAD and index), except that --hard also modifies your
working directory. If we're at C and run git reset --hard B, then the changes added in C, as well as any uncommitted
changes you have, will be removed, and the files in your working copy will match commit B. Since you can permanently
lose changes this way, you should always run git status before doing a hard reset to make sure your working directory is
clean or that you're okay with losing your uncommitted changes.
Reset
• git reset --hard <commit id>
resets the HEAD to any commit mentioned in command. And throws away all
your changes which is made after the commit corresponding to the commit id.

Más contenido relacionado

La actualidad más candente

Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagramsDilum Navanjana
 
Learning git
Learning gitLearning git
Learning gitSid Anand
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control SystemMohammad Imam Hossain
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHubNicolás Tourné
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsCarl Brown
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hubVenkat Malladi
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitLukas Fittl
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHubJames Gray
 
Git slides
Git slidesGit slides
Git slidesNanyak S
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Simplilearn
 

La actualidad más candente (20)

Git basics to advance with diagrams
Git basics to advance with diagramsGit basics to advance with diagrams
Git basics to advance with diagrams
 
Git real slides
Git real slidesGit real slides
Git real slides
 
git and github
git and githubgit and github
git and github
 
Learning git
Learning gitLearning git
Learning git
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
 
Git training v10
Git training v10Git training v10
Git training v10
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Starting with Git & GitHub
Starting with Git & GitHubStarting with Git & GitHub
Starting with Git & GitHub
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 
Github basics
Github basicsGithub basics
Github basics
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
Git for beginners
Git for beginnersGit for beginners
Git for beginners
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git slides
Git slidesGit slides
Git slides
 
Git & Github for beginners
Git & Github for beginnersGit & Github for beginners
Git & Github for beginners
 
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
Git Tutorial For Beginners | What is Git and GitHub? | DevOps Tools | DevOps ...
 

Similar a Git commands

Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheetAbdul Basit
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshopthemystic_ca
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control systemKumaresh Chandra Baruri
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commandsZakaria Bouazza
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptuallyseungzzang Kim
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?9 series
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubDSC GVP
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | WorkshopAnuchit Chalothorn
 
Git cheatsheet
Git cheatsheetGit cheatsheet
Git cheatsheetsynapsefre
 
Git Intermediate Course
Git Intermediate CourseGit Intermediate Course
Git Intermediate CourseAli Abbasi
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changesLearningTech
 
Git Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierGit Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierChristoph Matthies
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmdsrinathcox
 

Similar a Git commands (20)

Atlassian git cheatsheet
Atlassian git cheatsheetAtlassian git cheatsheet
Atlassian git cheatsheet
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
 
Introduction To Git Workshop
Introduction To Git WorkshopIntroduction To Git Workshop
Introduction To Git Workshop
 
Introduction to git, a version control system
Introduction to git, a version control systemIntroduction to git, a version control system
Introduction to git, a version control system
 
Git Memento of basic commands
Git Memento of basic commandsGit Memento of basic commands
Git Memento of basic commands
 
Pro git - grasping it conceptually
Pro git - grasping it conceptuallyPro git - grasping it conceptually
Pro git - grasping it conceptually
 
Git github
Git githubGit github
Git github
 
Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?Git Commands Every Developer Should Know?
Git Commands Every Developer Should Know?
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
 
Git cheatsheet
Git cheatsheetGit cheatsheet
Git cheatsheet
 
Git Intermediate Course
Git Intermediate CourseGit Intermediate Course
Git Intermediate Course
 
Git basics for beginners
Git basics for beginnersGit basics for beginners
Git basics for beginners
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Git commands
Git commandsGit commands
Git commands
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Git tutorial undoing changes
Git tutorial   undoing changesGit tutorial   undoing changes
Git tutorial undoing changes
 
Git Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easierGit Tricks — git utilities that make life git easier
Git Tricks — git utilities that make life git easier
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
Git learning
Git learningGit learning
Git learning
 

Más de Viyaan Jhiingade (7)

Rate limiting
Rate limitingRate limiting
Rate limiting
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
No sql
No sqlNo sql
No sql
 
Rest Webservice
Rest WebserviceRest Webservice
Rest Webservice
 
Storm
StormStorm
Storm
 
Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
Kafka RealTime Streaming
Kafka RealTime StreamingKafka RealTime Streaming
Kafka RealTime Streaming
 

Último

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 

Último (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
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
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Git commands

  • 1. git Most Used Commands
  • 2. GIT Commands Commands Description git --version To check version of Git installed. git config--system user.name <username> System level (All users on the system) git config --global user.name <username> Global level (for all the projects of a user) git config --local user.name <username> Local (default and specific for a repository) git config --global core.excludesfile %USERPROFILE%.gitignore . gitignore files should have the list of files to be ignored. git add . To add new and modified but not deleted. git add -u To add modified and deleted but not new files/directories
  • 3. GIT Commands Commands Description git Add -u To add modified and deleted and new files/directories. git commit --am “<message to commit> Creates a commit and adds files to staging. git commit --m “<message to commit> Creates a commit from staging. Assumes files already added to staging git init Creates .git subfolder in the project, which contains all necessary metadata git remote add origin https://github.com/Viyaan/<repository>.git To add a new repo git push origin <source_branch>:<destination branch> Actual syntax but the below syntax is enough git push -u origin <source branch name> push your changes to selected branch, since source and destination will always be same. It’s enough to mention only source branch.
  • 4. GIT Commands Commands Description git status gives status of tracked and untracked changes in your local repository. git branch list all available branches in local system. git branch -r list all branches in repository git branch <new branch name> create a new branch git checkout <branch name> switch to another branch git checkout -b <branch name> creates and switches to another branch git merge <branch name> Merges specified branch into current.
  • 5. GIT Commands Commands Description git rm <file name> To delete a file, you must commit and push after deleting. git diff <file-name> To see difference between uncommitted version to remote version of a file. git diff shows the changes you have done in your existing file (compare different versions of your files) git log Prints log of past commits git log --oneline Prints log of past commits in one line. git tag list all tags. git tag <tag name> create a tag. You need to push after new tag is created.
  • 6. GIT Commands Commands Description git branch -D <branch name> To delete a branch. You must push after delete command. git branch -d <branch name> Same as above but this time it will ask for confirmation If its not merged. git push origin :<destination branch> After deleting you must push and while pushing you should mention the destination branch. Destination branch is the branch u deleted. git tag -d <tag name> To delete a tag, use small d and not capital. git clone <clone url> To clone a repository git fetch origin To fetch new data from remote repository. But it doesn’t integrate any of those new data into your working files.
  • 7. GIT Commands Commands Description git pull pull not only downloads new data; it also directly integrates it into your current working copy files. git remote add <remote-name> <remote-url> To add a new remote, use the git remote add command on the terminal, in the directory your repository is stored at. git remote show To see number of remote repositories available. git stash Git stash temporarily shelves or stashes changes made to your working copy so you can work on something else, and come back and re-apply them later. git stash save <stash name> To save list of uncommitted changes in stash. git stash list List of stashes. git stash pop Apply changes which were stashed.
  • 8. GIT Commands Commands Description git commit --amend Modify the most recent commit git commit --amend -m "an updated commit message" Modify the most recent commit message git rev -parse HEAD Specify where head pointing too.
  • 9. Reset • git reset --soft <commit id> • git reset --mixed <commit id> • The difference between --mixed and --soft is whether or not your index is also modified. So, if we're on branch master with this series of commits: • - A - B - C (master) • HEADpoints to C and the index matches C. • When we run git reset --soft B, master (and thus HEAD) now points to B, but the index still has the changes from C; git status will show them as staged. So if we run git commit at this point, we'll get a new commit with the same changes as C. • ________________________________________ • Okay, so starting from here again: • - A - B - C (master) • Now let's do git reset --mixed B. (Note: --mixed is the default option). Once again, master and HEAD point to B, but this time the index is also modified to match B. If we run git commit at this point, nothing will happen since the index matches HEAD. We still have the changes in the working directory, but since they're not in the index, git status shows them as unstaged. To commit them, you would git add and then commit as usual. • ________________________________________ • And finally, --hard is the same as --mixed (it changes your HEAD and index), except that --hard also modifies your working directory. If we're at C and run git reset --hard B, then the changes added in C, as well as any uncommitted changes you have, will be removed, and the files in your working copy will match commit B. Since you can permanently lose changes this way, you should always run git status before doing a hard reset to make sure your working directory is clean or that you're okay with losing your uncommitted changes.
  • 10. Reset • git reset --hard <commit id> resets the HEAD to any commit mentioned in command. And throws away all your changes which is made after the commit corresponding to the commit id.