SlideShare uma empresa Scribd logo
1 de 27
Code Version Control (Git)
By Ren Sothearin
Prerequisite
● Basic Linux Command (Optional)
● Familiar with Command Prompt/ Terminal
● Have GitLab/ GitHub/ Bitbucket Account
● Commitment to solve the conflict ^^
IDE
● (Windows) : required to use GitBash.
○ Download link: https://git-scm.com/downloads
● (Mac) : can use Mac Terminal, (optional) install “ohmyz.sh”
○ Go to terminal and add “$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-
zsh/master/tools/install.sh)"”
What is Git?
Git (/ɡɪt/) is a version control system (VCS) for tracking changes in computer files and
coordinating work on those files among multiple people. It is primarily used for
software development, but it can be used to keep track of changes in any files. As a
distributed revision control system it is aimed at speed, data integrity, and support for
distributed, non-linear workflows.
When was it invented?
Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with
other kernel developers contributing to its initial development. Its current maintainer
since 2005 is Junio Hamano.
What are the specialities in Git?
As with most other distributed version control systems, and unlike most client–server
systems, every Git directory on every computer is a full-fledged repository with
complete history and full version tracking abilities, independent of network access or a
central server.
Note: Git is free software distributed under the terms of the GNU General Public
License version 2
Git Web Interface
1. Famous
a. GitHub
b. GitLab
c. Bitbucket
2. Not familiar
Gitweb, Wit, Cgit, Gitorious,
Trac, Kallithea, Stash,
Springloops, Bonobo Git
Server
How to use
--distributed-even-if-your-workflow-isnt
Why GitLab?
https://about.gitlab.com/
● Free unlimited (Private)
repositories
● Free unlimited collaborators
● Friendly Interface
Basic Keyword
master - the repository’s main branch. Depending on the work flow it is the one people
work on or the one where the integration happens
clone - copies an existing git repository, normally from some remote location to your
local environment.
commit - submitting files to the repository (the local one); in other VCS it is often
referred to as “checkin”
fetch or pull - is like “update” or “get latest” in other VCS. The difference between fetch
and pull is that pull combines both, fetching the latest code from a remote repo as
Basic Keyword
push - is used to submit the code to a remote repository
remote - these are “remote” locations of your repository, normally on some central
server.
head - is a reference to the node to which our working space of the repository currently
points.
branch - is just like in other VCS with the difference that a branch in Git is actually
nothing more special than a particular label on a given node. It is not a physical copy
of the files as in other popular VCS.
Git Configuration
$ git config --global user.name "username": to config username with the git remote
repository
$ git config --global user.email example@example.com: to config username and email
with the git remote repository
$ git init : is used to initialize git in your local repository
Cloning project from a remote repository
$ git clone <remote_repo> : is used to clone the remote repository into local (clone
means copy)
Example: $ git clone git@gitlab.com:user/myproject.git
$ git clone -b <branch> <remote_repo> : is used to clone from a specific branch at the
remote repository into local
Example: $ git clone -b feature git@gitlab.com:user/myproject.git
This example means that we clone from branch “feature” at the remote
repository name “myproject”.
Adding file to a remote repository
$ git add <file_name> : is used to add the specific file name to the remote repository
$ git add . : is used to add all the changed file to the remote repository (Git will take a
snapshot of the contents of all files under the current directory (note the .))
$ git add -a/ $ git add -A : it will find new files as well as staging modified content and
removing files that are no longer in the working tree.
$ git add --all : the same as git add -a
$ git add * : the same as git add .
Committing file to a remote repository
$ git commit -m “message” : is used to commit the changes to head (but not yet to the
remote repository)
$ git commit -a : Commit any files you've added with git add, and also commit any files
you've changed since then
Pushing files to a remote repository
$ git push -u origin <branch_name> : is used to push the branch to your remote
repository, so others can use it.
Example: git push -u origin master
● $ git push origin <branch_name> : is used to push the branch to your remote
repository, so others can use it.
Example: git push origin master
● $ git push --all origin : is used to push all branches to your remote repository
Pulling files from a remote repository
$ git pull : is used to pull the fast-forwards codes, files from the our own branch
Example: myproject (master) $ git pull
This means that we pull our own code from the remote repo into local
● $ git pull origin <branch_name> : is used to pull the fast-forwards codes, files from
the remote branch into our local
Example: myproject (master) $ git pull origin feature
Meaning, stands on “master’ branch and pull from “feature” branch
Git branch
$ git branch “branch_name” : is used to create a new branch name, after create we still
stand on the current branch
Example: myproject (master) $ git branch “feature” : means that we stands on
master and create a new branch called “feature”
● $ git checkout -b “branch_name” : is used to checkout and create a new branch
name, after create we change the current standing branch to the new branch
Example: myproject (master) $ git checkout -b “feature”
myproject (feature) $
Git branch
$ git branch : List all the branches in your repo, and also tell you what branch you're
currently in
Example: myproject (master) $ git branch
feature
*master
● $ git checkout <branch_name> : Switch from one branch to another branch
Example: myproject (master) $ git checkout feature
Git branch
$ git branch -d <branch_name> : is used to delete branch in the remote repo
Merging branch together
$ git merge <branch_name> : is used to merge a different branch into your active
branch.
Example: myproject (master) $ git merge feature
Means that we are merging “feature” into “master”
● $ git diff <source branch> <target branch> : is used to preview change on branch
before merge
Git fetch
$ git fetch : is used to fetch the changes in other branch into your current active branch
$ git fetch <branch_name> : is used to fetch the changes in the specific branch into your
current active branch
Undo local change
$ git checkout --<file_name> : is used to undo your local change in the file. If you mess
up, you can replace the changes in your working tree with the last content in head.
Changes already added to the index, as well as new files, will be kept.
Instead, to drop all your local changes and commits, fetch the latest history from the
server and point your local master branch at it, do this
$ git fetch origin
$ git reset --hard origin/master
Git log
$ git log : is used to see the changing history
$ git log -p : is used to see complete diffs at each step
Stash local change
$ git stash : is used to stash the local change that you have made in your local
repository. When you stash your code, your local change will remove and your tree
will look the same as what you have committed. After you stash dont worry that you
will lose your code, it just put somewhere in your computer.
$ git stash pop : is used to get what you stash back into your local repository. You can
get it back, but if you “git status” you won’t see any change file.
$ git reset HEAD <file> : is used get what you stash back after “stash pop”
Contact
Sothearin Ren
ren.sothearin@gmail.com
https://gitlab.com/Sothearin

Mais conteúdo relacionado

Mais procurados (20)

Git: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commandsGit: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commands
 
GIT in a nutshell
GIT in a nutshellGIT in a nutshell
GIT in a nutshell
 
Android Libs - Retrofit
Android Libs - RetrofitAndroid Libs - Retrofit
Android Libs - Retrofit
 
Working in Team using Git in Unity
Working in Team using Git in UnityWorking in Team using Git in Unity
Working in Team using Git in Unity
 
Bitbucket
BitbucketBitbucket
Bitbucket
 
390a gitintro 12au
390a gitintro 12au390a gitintro 12au
390a gitintro 12au
 
Basic Git
Basic GitBasic Git
Basic Git
 
Introduction to Git and GitHub
Introduction to Git and GitHubIntroduction to Git and GitHub
Introduction to Git and GitHub
 
Git & GitHub WorkShop
Git & GitHub WorkShopGit & GitHub WorkShop
Git & GitHub WorkShop
 
GIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control SystemGIT: Content-addressable filesystem and Version Control System
GIT: Content-addressable filesystem and Version Control System
 
GIT | Distributed Version Control System
GIT | Distributed Version Control SystemGIT | Distributed Version Control System
GIT | Distributed Version Control System
 
Git and GitHub
Git and GitHubGit and GitHub
Git and GitHub
 
Git introduction
Git introductionGit introduction
Git introduction
 
Git
GitGit
Git
 
Git and github
Git and githubGit and github
Git and github
 
Git training
Git trainingGit training
Git training
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
Github
GithubGithub
Github
 
HackMTY - GitHub Workshop
HackMTY - GitHub WorkshopHackMTY - GitHub Workshop
HackMTY - GitHub Workshop
 
Git and Github
Git and GithubGit and Github
Git and Github
 

Semelhante a Understanding about git

Semelhante a Understanding about git (20)

Git basic
Git basicGit basic
Git basic
 
Git and github 101
Git and github 101Git and github 101
Git and github 101
 
Git setuplinux
Git setuplinuxGit setuplinux
Git setuplinux
 
GitSetupLinux
GitSetupLinuxGitSetupLinux
GitSetupLinux
 
Hacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHubHacktoberfest intro to Git and GitHub
Hacktoberfest intro to Git and GitHub
 
sample.pptx
sample.pptxsample.pptx
sample.pptx
 
Git and Github workshop GDSC MLRITM
Git and Github  workshop GDSC MLRITMGit and Github  workshop GDSC MLRITM
Git and Github workshop GDSC MLRITM
 
Learn Git Basics
Learn Git BasicsLearn Git Basics
Learn Git Basics
 
Git cheatsheet
Git cheatsheetGit cheatsheet
Git cheatsheet
 
Git
GitGit
Git
 
1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx1-Intro to VC & GIT PDF.pptx
1-Intro to VC & GIT PDF.pptx
 
簡單介紹git
簡單介紹git簡單介紹git
簡單介紹git
 
Git 101
Git 101Git 101
Git 101
 
Git tutorial
Git tutorialGit tutorial
Git tutorial
 
Version control with GIT
Version control with GITVersion control with GIT
Version control with GIT
 
Introduction to Git and Github
Introduction to Git and Github Introduction to Git and Github
Introduction to Git and Github
 
A Quick Start - Version Control with Git
A Quick Start - Version Control with GitA Quick Start - Version Control with Git
A Quick Start - Version Control with Git
 
Git 入门与实践
Git 入门与实践Git 入门与实践
Git 入门与实践
 
Git
GitGit
Git
 
Learning git
Learning gitLearning git
Learning git
 

Último

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...kalichargn70th171
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
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
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 

Último (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
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
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 

Understanding about git

  • 1. Code Version Control (Git) By Ren Sothearin
  • 2. Prerequisite ● Basic Linux Command (Optional) ● Familiar with Command Prompt/ Terminal ● Have GitLab/ GitHub/ Bitbucket Account ● Commitment to solve the conflict ^^
  • 3. IDE ● (Windows) : required to use GitBash. ○ Download link: https://git-scm.com/downloads ● (Mac) : can use Mac Terminal, (optional) install “ohmyz.sh” ○ Go to terminal and add “$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my- zsh/master/tools/install.sh)"”
  • 4. What is Git? Git (/ɡɪt/) is a version control system (VCS) for tracking changes in computer files and coordinating work on those files among multiple people. It is primarily used for software development, but it can be used to keep track of changes in any files. As a distributed revision control system it is aimed at speed, data integrity, and support for distributed, non-linear workflows.
  • 5. When was it invented? Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development. Its current maintainer since 2005 is Junio Hamano.
  • 6. What are the specialities in Git? As with most other distributed version control systems, and unlike most client–server systems, every Git directory on every computer is a full-fledged repository with complete history and full version tracking abilities, independent of network access or a central server. Note: Git is free software distributed under the terms of the GNU General Public License version 2
  • 7. Git Web Interface 1. Famous a. GitHub b. GitLab c. Bitbucket 2. Not familiar Gitweb, Wit, Cgit, Gitorious, Trac, Kallithea, Stash, Springloops, Bonobo Git Server
  • 8.
  • 10. Why GitLab? https://about.gitlab.com/ ● Free unlimited (Private) repositories ● Free unlimited collaborators ● Friendly Interface
  • 11. Basic Keyword master - the repository’s main branch. Depending on the work flow it is the one people work on or the one where the integration happens clone - copies an existing git repository, normally from some remote location to your local environment. commit - submitting files to the repository (the local one); in other VCS it is often referred to as “checkin” fetch or pull - is like “update” or “get latest” in other VCS. The difference between fetch and pull is that pull combines both, fetching the latest code from a remote repo as
  • 12. Basic Keyword push - is used to submit the code to a remote repository remote - these are “remote” locations of your repository, normally on some central server. head - is a reference to the node to which our working space of the repository currently points. branch - is just like in other VCS with the difference that a branch in Git is actually nothing more special than a particular label on a given node. It is not a physical copy of the files as in other popular VCS.
  • 13. Git Configuration $ git config --global user.name "username": to config username with the git remote repository $ git config --global user.email example@example.com: to config username and email with the git remote repository $ git init : is used to initialize git in your local repository
  • 14. Cloning project from a remote repository $ git clone <remote_repo> : is used to clone the remote repository into local (clone means copy) Example: $ git clone git@gitlab.com:user/myproject.git $ git clone -b <branch> <remote_repo> : is used to clone from a specific branch at the remote repository into local Example: $ git clone -b feature git@gitlab.com:user/myproject.git This example means that we clone from branch “feature” at the remote repository name “myproject”.
  • 15. Adding file to a remote repository $ git add <file_name> : is used to add the specific file name to the remote repository $ git add . : is used to add all the changed file to the remote repository (Git will take a snapshot of the contents of all files under the current directory (note the .)) $ git add -a/ $ git add -A : it will find new files as well as staging modified content and removing files that are no longer in the working tree. $ git add --all : the same as git add -a $ git add * : the same as git add .
  • 16. Committing file to a remote repository $ git commit -m “message” : is used to commit the changes to head (but not yet to the remote repository) $ git commit -a : Commit any files you've added with git add, and also commit any files you've changed since then
  • 17. Pushing files to a remote repository $ git push -u origin <branch_name> : is used to push the branch to your remote repository, so others can use it. Example: git push -u origin master ● $ git push origin <branch_name> : is used to push the branch to your remote repository, so others can use it. Example: git push origin master ● $ git push --all origin : is used to push all branches to your remote repository
  • 18. Pulling files from a remote repository $ git pull : is used to pull the fast-forwards codes, files from the our own branch Example: myproject (master) $ git pull This means that we pull our own code from the remote repo into local ● $ git pull origin <branch_name> : is used to pull the fast-forwards codes, files from the remote branch into our local Example: myproject (master) $ git pull origin feature Meaning, stands on “master’ branch and pull from “feature” branch
  • 19. Git branch $ git branch “branch_name” : is used to create a new branch name, after create we still stand on the current branch Example: myproject (master) $ git branch “feature” : means that we stands on master and create a new branch called “feature” ● $ git checkout -b “branch_name” : is used to checkout and create a new branch name, after create we change the current standing branch to the new branch Example: myproject (master) $ git checkout -b “feature” myproject (feature) $
  • 20. Git branch $ git branch : List all the branches in your repo, and also tell you what branch you're currently in Example: myproject (master) $ git branch feature *master ● $ git checkout <branch_name> : Switch from one branch to another branch Example: myproject (master) $ git checkout feature
  • 21. Git branch $ git branch -d <branch_name> : is used to delete branch in the remote repo
  • 22. Merging branch together $ git merge <branch_name> : is used to merge a different branch into your active branch. Example: myproject (master) $ git merge feature Means that we are merging “feature” into “master” ● $ git diff <source branch> <target branch> : is used to preview change on branch before merge
  • 23. Git fetch $ git fetch : is used to fetch the changes in other branch into your current active branch $ git fetch <branch_name> : is used to fetch the changes in the specific branch into your current active branch
  • 24. Undo local change $ git checkout --<file_name> : is used to undo your local change in the file. If you mess up, you can replace the changes in your working tree with the last content in head. Changes already added to the index, as well as new files, will be kept. Instead, to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it, do this $ git fetch origin $ git reset --hard origin/master
  • 25. Git log $ git log : is used to see the changing history $ git log -p : is used to see complete diffs at each step
  • 26. Stash local change $ git stash : is used to stash the local change that you have made in your local repository. When you stash your code, your local change will remove and your tree will look the same as what you have committed. After you stash dont worry that you will lose your code, it just put somewhere in your computer. $ git stash pop : is used to get what you stash back into your local repository. You can get it back, but if you “git status” you won’t see any change file. $ git reset HEAD <file> : is used get what you stash back after “stash pop”