SlideShare a Scribd company logo
GIT BASIC
git init
This will create a .git repository in project. A repository or "repo" is a collection of
all the changes we’ve made to our project over time and will build a history of
these changes. This is the first thing we want to do with a new project.
Empty Directory before git init
.git Directory After git init
.git directory structure
HEAD file:
holds a reference to the branch you are currently on. This tells Git what
to use as the parent of your next commit.
Config file:
the main Git configuration file
Description file:
file is only used by the GitWeb program ( to display the description of
the repo on the GitWeb page). GitWeb - Git web interface (web frontend
to Git repositories).
hooks:
This directory contains shell scripts that are invoked after the
corresponding Git commands. For example, after you run a commit, Git
will try to execute the post-commit script
info:
Additional information about the repository is recorded in this directory.
objects:
In this directory the data of your Git objects is stored – all the contents
of the files you have ever checked in, your commits, trees and tag
objects.
refs: References are stored in subdirectories of this directory(i.e:
heads, tags)
Create files and folders or use exist files and folder
git add
Adds files changes in our working directory to our index
git add filename
add specify file in staging area or index.
git add .
add everything from the project folder to staging area or
index.
git commit
Takes the files from our staging area or index
and commits them to our local repository.
commit title
git commit -m “title about commit”
commit title and description
git commit -m “title” -m “description”
-m for message
First -m for title only
Second -m for description
git status
Shows you the status of files in the index versus the working directory. It will list out files
that are untracked (only in your working directory), modified (tracked but not yet updated
in your index), and staged (added to your index and ready for committing).
git status
before add file in index to local repo
git status
after add file into local repo from index
Create github Repo
Code hosting platform
1. Github: https://github.com
2. Bitbucket: https://bitbucket.org/
3. Gitlab: https://about.gitlab.com/
Creating new repository on github
After Repo Create on github
before pushed anything
git remote add origin __path__
This adds the location of our remote repository. Everything up until now has been on our local repository on our
computer
git remote
show remote path
git remote -v
show remote path with details
git push
Pushes all the modified local objects to the remote repository and advances its
branches
git push origin master
push all modification on master branch
git push origin head
HEAD points to the top of the current
branch. But we don't have to remember/type
the current branch name. Also it prevents we
from pushing to the wrong remote branch by accident.
git push -u origin head
Push changes to remote repository
(and remember the branch)
-u means --set-upstream
After push code from local to
remote(github)
git pull
Fetches the files from the remote repository and merges it
with our local one. Show all change between remote
branch and local branch.
git pull origin head
Fetches the files from the remote branch and merges it
with our local current branch.
remote branch == local branch
git pull origin master(or any)
Fetches the files from the remote master branch
and merges it with our local current branch.
remote branch(master) != local branch(dev or any)
git remote repo path
git clone {remote path}
Example: git clone https://github.com/akbaruddin/gittutorial.git
Creates a GIT repository copy from a remote source. Also adds the original location as a remote so we can fetch from it again and push
to it if you have permissions
git branch
Show list of exist branches.
git branch -vv
list mode, show sha1 and commit subject line for each head, along with
relationship to upstream branch (if any). Twice, print the name of the
upstream branch
git branch -a
Show list of exist branches, including remote branches
Create new branch
git checkout -b {branch_name}
Example: git checkout -b dev
Create new branch and switch.
git checkout -b {branch_name} {specific_branch}
Example: git checkout -b fix__dev dev
Create new branch from another specific branch without going that
branch and switch to new branch.
Branch naming
reason__details--tag
Reason: label must be identical to the purpose of the branch
● feature/new_feature
● fix/hotfix/patch
● refactor
● enhancement/optimisation
● delete/remove/undo
● update
● Content change
Details: A two or three short-word descriptions about the branch. Avoid long descriptive names for branches. Make them
as short and descriptive as possible.
fix__signup-routing
fix__duplicate-images
Tag: It is optional and can be used under special circumstance(any external tracker or extra details).
feature__public-api--v2
fix__file-uploader--pdf
Switch branch & Discard changes of file
git checkout {branch_name}
Example: git checkout dev
git checkout -
Example: git checkout -
Switch to the branch last checked out
git checkout -- {file_name}
Example: git checkout -- README.md
Discard changes to a file
Delete branch
git branch -d {branch_name}
Example: git branch -d dev
All codebase merged with main codebase we can delete branch
without losing any history, if hasn’t been merged, command gives an
error message.
git branch -D {branch_name}
Example: git branch -D fix__login
Experiment failed, we want to remove the branch
with regardless of its status, -D remove branch
without any warning
git log
Example: git log
Shows a listing of commits on a branch including the corresponding details.
git diff
Example:
git diff # show all file differences
git diff README.md # Specific file difference
Generates patch files or statistics of differences between paths or files in our git repository, or our
index or our working directory
git merge
Example:
git merge master # git merge {source_branch_name}
Merge a branch into the active branch
git merge master dev # git merge {source_branch_name} {target_branch_name}
Merge a branch into a target branch
git stash
Example:
git stash | git stash save
Save changes and return to clean branch
git stash apply
Apply saved changes without remove of saved change
git stash pop
Apply saved changes, also remove changes from list
git stash list
Show all list of stashes
git stash clear
remove all stashes
git rm
Example:
git rm -r README.md # git rm -r {file_name}
Removes files from your index and your working directory
so they will not be tracked
git reset
Example:
git reset --hard HEAD
Resets our index and working directory to the state of our
last commit
Ad

More Related Content

What's hot (20)

Jenkins Introduction
Jenkins IntroductionJenkins Introduction
Jenkins Introduction
Pavan Gupta
 
Git workflows presentation
Git workflows presentationGit workflows presentation
Git workflows presentation
Mack Hardy
 
Git real slides
Git real slidesGit real slides
Git real slides
Lucas Couto
 
git and github
git and githubgit and github
git and github
Darren Oakley
 
Git Introduction
Git IntroductionGit Introduction
Git Introduction
Gareth Hall
 
Git branching strategies
Git branching strategiesGit branching strategies
Git branching strategies
jstack
 
Git
GitGit
Git
Mayank Patel
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
Tilton2
 
Git and Github
Git and GithubGit and Github
Git and Github
Wen-Tien Chang
 
Jenkins tutorial
Jenkins tutorialJenkins tutorial
Jenkins tutorial
Mamun Rashid, CCDH
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
Majid Hosseini
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
littlebtc
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
PingLun Liao
 
Git in 10 minutes
Git in 10 minutesGit in 10 minutes
Git in 10 minutes
Safique Ahmed Faruque
 
Introduction git
Introduction gitIntroduction git
Introduction git
Dian Sigit Prastowo
 
Introduction to GitHub Actions
Introduction to GitHub ActionsIntroduction to GitHub Actions
Introduction to GitHub Actions
Knoldus Inc.
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
James Gray
 
Introduzione a Git (ITA - 2017)
Introduzione a Git (ITA - 2017)Introduzione a Git (ITA - 2017)
Introduzione a Git (ITA - 2017)
Valerio Radice
 
Git Series. Episode 3. Git Flow and Github-Flow
Git Series. Episode 3. Git Flow and Github-FlowGit Series. Episode 3. Git Flow and Github-Flow
Git Series. Episode 3. Git Flow and Github-Flow
Mikhail Melnik
 
Tutoriel GIT
Tutoriel GITTutoriel GIT
Tutoriel GIT
Francois ANDRE
 
Jenkins Introduction
Jenkins IntroductionJenkins Introduction
Jenkins Introduction
Pavan Gupta
 
Git workflows presentation
Git workflows presentationGit workflows presentation
Git workflows presentation
Mack Hardy
 
Git Introduction
Git IntroductionGit Introduction
Git Introduction
Gareth Hall
 
Git branching strategies
Git branching strategiesGit branching strategies
Git branching strategies
jstack
 
Git and Github slides.pdf
Git and Github slides.pdfGit and Github slides.pdf
Git and Github slides.pdf
Tilton2
 
Git and git workflow best practice
Git and git workflow best practiceGit and git workflow best practice
Git and git workflow best practice
Majid Hosseini
 
寫給大家的 Git 教學
寫給大家的 Git 教學寫給大家的 Git 教學
寫給大家的 Git 教學
littlebtc
 
Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹Git 程式碼版本控制軟體介紹
Git 程式碼版本控制軟體介紹
PingLun Liao
 
Introduction to GitHub Actions
Introduction to GitHub ActionsIntroduction to GitHub Actions
Introduction to GitHub Actions
Knoldus Inc.
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
James Gray
 
Introduzione a Git (ITA - 2017)
Introduzione a Git (ITA - 2017)Introduzione a Git (ITA - 2017)
Introduzione a Git (ITA - 2017)
Valerio Radice
 
Git Series. Episode 3. Git Flow and Github-Flow
Git Series. Episode 3. Git Flow and Github-FlowGit Series. Episode 3. Git Flow and Github-Flow
Git Series. Episode 3. Git Flow and Github-Flow
Mikhail Melnik
 

Similar to Git basic (20)

Git training
Git trainingGit training
Git training
eric7master
 
Understanding about git
Understanding about gitUnderstanding about git
Understanding about git
Sothearin Ren
 
Git commands
Git commandsGit commands
Git commands
Javed Hussain
 
Git introduction
Git introductionGit introduction
Git introduction
satyendrajaladi
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
Nguyen Van Hung
 
Git SCM
Git SCMGit SCM
Git SCM
Stefan Prutianu
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
DSC GVP
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
UshaSuray
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
Senthilkumar Gopal
 
Git like a pro EDD18 - Full edition
Git like a pro EDD18 - Full editionGit like a pro EDD18 - Full edition
Git like a pro EDD18 - Full edition
Jesús Miguel Benito Calzada
 
Git slides
Git slidesGit slides
Git slides
Nanyak S
 
Contributing to Open Source with GitHub GDSC
Contributing to Open Source with GitHub GDSCContributing to Open Source with GitHub GDSC
Contributing to Open Source with GitHub GDSC
AyanMasood1
 
Exprimiendo GIT
Exprimiendo GITExprimiendo GIT
Exprimiendo GIT
betabeers
 
Version Control & Git
Version Control & GitVersion Control & Git
Version Control & Git
Jason Byrne
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
Prakash Dantuluri
 
GIT Basics
GIT BasicsGIT Basics
GIT Basics
Tagged Social
 
Git basics for beginners
Git basics for beginnersGit basics for beginners
Git basics for beginners
PravallikaTammisetty
 
Git
GitGit
Git
Terry Wang
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
Terry Wang
 
Git and github
Git and githubGit and github
Git and github
Teodora Ahkozidou
 
Ad

Recently uploaded (20)

TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage DashboardsAdobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
Adobe Marketo Engage Champion Deep Dive - SFDC CRM Synch V2 & Usage Dashboards
BradBedford3
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
F-Secure Freedome VPN 2025 Crack Plus Activation  New VersionF-Secure Freedome VPN 2025 Crack Plus Activation  New Version
F-Secure Freedome VPN 2025 Crack Plus Activation New Version
saimabibi60507
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
How can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptxHow can one start with crypto wallet development.pptx
How can one start with crypto wallet development.pptx
laravinson24
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Ad

Git basic

  • 2. git init This will create a .git repository in project. A repository or "repo" is a collection of all the changes we’ve made to our project over time and will build a history of these changes. This is the first thing we want to do with a new project.
  • 5. .git directory structure HEAD file: holds a reference to the branch you are currently on. This tells Git what to use as the parent of your next commit. Config file: the main Git configuration file Description file: file is only used by the GitWeb program ( to display the description of the repo on the GitWeb page). GitWeb - Git web interface (web frontend to Git repositories). hooks: This directory contains shell scripts that are invoked after the corresponding Git commands. For example, after you run a commit, Git will try to execute the post-commit script info: Additional information about the repository is recorded in this directory. objects: In this directory the data of your Git objects is stored – all the contents of the files you have ever checked in, your commits, trees and tag objects. refs: References are stored in subdirectories of this directory(i.e: heads, tags)
  • 6. Create files and folders or use exist files and folder
  • 7. git add Adds files changes in our working directory to our index git add filename add specify file in staging area or index. git add . add everything from the project folder to staging area or index.
  • 8. git commit Takes the files from our staging area or index and commits them to our local repository. commit title git commit -m “title about commit” commit title and description git commit -m “title” -m “description” -m for message First -m for title only Second -m for description
  • 9. git status Shows you the status of files in the index versus the working directory. It will list out files that are untracked (only in your working directory), modified (tracked but not yet updated in your index), and staged (added to your index and ready for committing).
  • 10. git status before add file in index to local repo git status after add file into local repo from index
  • 11. Create github Repo Code hosting platform 1. Github: https://github.com 2. Bitbucket: https://bitbucket.org/ 3. Gitlab: https://about.gitlab.com/
  • 13. After Repo Create on github before pushed anything
  • 14. git remote add origin __path__ This adds the location of our remote repository. Everything up until now has been on our local repository on our computer
  • 15. git remote show remote path git remote -v show remote path with details
  • 16. git push Pushes all the modified local objects to the remote repository and advances its branches git push origin master push all modification on master branch git push origin head HEAD points to the top of the current branch. But we don't have to remember/type the current branch name. Also it prevents we from pushing to the wrong remote branch by accident. git push -u origin head Push changes to remote repository (and remember the branch) -u means --set-upstream
  • 17. After push code from local to remote(github)
  • 18. git pull Fetches the files from the remote repository and merges it with our local one. Show all change between remote branch and local branch. git pull origin head Fetches the files from the remote branch and merges it with our local current branch. remote branch == local branch git pull origin master(or any) Fetches the files from the remote master branch and merges it with our local current branch. remote branch(master) != local branch(dev or any)
  • 20. git clone {remote path} Example: git clone https://github.com/akbaruddin/gittutorial.git Creates a GIT repository copy from a remote source. Also adds the original location as a remote so we can fetch from it again and push to it if you have permissions
  • 21. git branch Show list of exist branches. git branch -vv list mode, show sha1 and commit subject line for each head, along with relationship to upstream branch (if any). Twice, print the name of the upstream branch git branch -a Show list of exist branches, including remote branches
  • 22. Create new branch git checkout -b {branch_name} Example: git checkout -b dev Create new branch and switch. git checkout -b {branch_name} {specific_branch} Example: git checkout -b fix__dev dev Create new branch from another specific branch without going that branch and switch to new branch.
  • 23. Branch naming reason__details--tag Reason: label must be identical to the purpose of the branch ● feature/new_feature ● fix/hotfix/patch ● refactor ● enhancement/optimisation ● delete/remove/undo ● update ● Content change Details: A two or three short-word descriptions about the branch. Avoid long descriptive names for branches. Make them as short and descriptive as possible. fix__signup-routing fix__duplicate-images Tag: It is optional and can be used under special circumstance(any external tracker or extra details). feature__public-api--v2 fix__file-uploader--pdf
  • 24. Switch branch & Discard changes of file git checkout {branch_name} Example: git checkout dev git checkout - Example: git checkout - Switch to the branch last checked out git checkout -- {file_name} Example: git checkout -- README.md Discard changes to a file
  • 25. Delete branch git branch -d {branch_name} Example: git branch -d dev All codebase merged with main codebase we can delete branch without losing any history, if hasn’t been merged, command gives an error message. git branch -D {branch_name} Example: git branch -D fix__login Experiment failed, we want to remove the branch with regardless of its status, -D remove branch without any warning
  • 26. git log Example: git log Shows a listing of commits on a branch including the corresponding details.
  • 27. git diff Example: git diff # show all file differences git diff README.md # Specific file difference Generates patch files or statistics of differences between paths or files in our git repository, or our index or our working directory
  • 28. git merge Example: git merge master # git merge {source_branch_name} Merge a branch into the active branch git merge master dev # git merge {source_branch_name} {target_branch_name} Merge a branch into a target branch
  • 29. git stash Example: git stash | git stash save Save changes and return to clean branch git stash apply Apply saved changes without remove of saved change git stash pop Apply saved changes, also remove changes from list git stash list Show all list of stashes git stash clear remove all stashes
  • 30. git rm Example: git rm -r README.md # git rm -r {file_name} Removes files from your index and your working directory so they will not be tracked
  • 31. git reset Example: git reset --hard HEAD Resets our index and working directory to the state of our last commit