SlideShare a Scribd company logo
Version
Control
GIT
DevOps course by Abdul Rahim
Basic Git Commands
DevOps course by Abdul Rahim
git --version git init git merge
git config --list git add <options> git rebase
git config --help git rm/mv <options> git push
git config --global git commit <options> git pull
git log git diff git checkout
git status git reset git fetch
git stash git branch git add origin
git stash apply
Git Branching Strategy /
Workflow
DevOps course by Abdul Rahim
Build your strategy from these three concepts:
– Use feature branches for all new features and bug fixes.
– Merge feature branches into the main branch using pull
requests.
– Keep a high quality, up-to-date main branch.
Git Branching Strategy /
Workflow
DevOps course by Abdul Rahim
Git Branching
DevOps course by Abdul Rahim
– Independent/isolated line of development
– Inexpensive/lightweight as compared to other VCS
– Way to work on different version of a repository
– Work in parallel
– Master is the default branch
– Branches are just pointers to commits
– Protected branches
Branching Model
DevOps course by Abdul Rahim
Git Branching Commands
DevOps course by Abdul Rahim
– List Branches: git branch
– List all Branches: git branch -a
– Create Branch: git branch [branch_name]
– Delete Branch: git branch -d [branch_name]
– Delete remote Branch: git push origin --delete [branch_name]
– Create Branch and Switch: git checkout -b [branch_name]
– Switch Branch: git checkout [branch_name]
LAB - Branching
DevOps course by Abdul Rahim
1. Create Branch
2. List Branches
3. Switch Branch
4. Commit to new Branch
5. Rename Branch
6. Delete Branch
LAB 1- Create Branch
DevOps course by Abdul Rahim
– Create a new branch called “test-branch” by using
the command:
git branch test-branch
LAB 2- List Branch
DevOps course by Abdul Rahim
– List local branches by using the command:
– git branch OR git branch --list
– List remote branches by using the command:
– git branch -r
– List all branches by using the command:
– git branch -a
LAB 3- Switch Branch
DevOps course by Abdul Rahim
– In order to commit to new branch, first you will have to
switch to newly created branch, using the command:
git branch test-branch
– To know about current branch run the command:
git status
LAB 4- Commit to New
Branch
DevOps course by Abdul Rahim
– You have already switched to testing branch. Next
create a file “test-branch.txt” in new branch and
commit by using the command:
git add test-branch.txt
git commit -m "create test-branch.txt file for test-branch"
LAB 5- Rename Branch
DevOps course by Abdul Rahim
– Rename the “test-branch” branch to “new-test-
branch” using the command:
git branch -m test-branch new-test-branch
LAB 6- Delete Branch
DevOps course by Abdul Rahim
– In order to delete the branch first you will have to switch
to another branch i.e. master in this case.
git checkout master
– Delete the “new-test-branch” branch using the
command:
git branch -d new-test-branch
Git Merging
DevOps course by Abdul Rahim
Git Merging
DevOps course by Abdul Rahim
– Combine multiple branches into one
– Combines multiple sequence into unified history
– Commands
– Merge branch into active branch: git merge [branch-name]
– Merge branch into target branch: git merge [source-branch] [target-
branch]
MERGING - FAST
FORWARD
DevOps course by Abdul Rahim
MERGING – 3 Way
DevOps course by Abdul Rahim
MERGING – Resolving
Conflict
DevOps course by Abdul Rahim
LAB - Merging
DevOps course by Abdul Rahim
1. Fast Forward merge
2. Three way (3 Way) Merge
3. Resolving Conflict
Lab 1- Fast Forward
Merge
DevOps course by Abdul Rahim
You will first create a new branch and then add commit to
it and then merge new branch to master branch.
– Create a new branch and checkout:
– git checkout -b ffm-branch
– Create a new file, add, and commit to branch:
– git add merge-ff.txt
– git commit -m “add merge-ff.txt”
Lab 1- Fast Forward
Merge
DevOps course by Abdul Rahim
– Merge “ffm-branch” to master branch:
– git checkout master
– git merge ffm-branch
– Check master logs for fast forward merge:
– git log --oneline --graph –decorate
– Delete “ffm-branch” branch:
– git branch -d ffm-branch
Lab 2- Three Way Merge
DevOps course by Abdul Rahim
– You will first create a branch, then make a commit to it, then
switch to master branch and make a commit to it so that it
moves ahead from where the new branch was created, then
merge new branch to master.
– Create a new branch and checkout:
– git checkout -b twm-branch master
– Create a new file, add, and commit to branch:
– git add merge-tw.txt
– git commit -m “add merge-tw.txt”
Lab 2- Three Way Merge
DevOps course by Abdul Rahim
– Move to master branch
– git checkout master
– Create a new file, add, and commit to branch:
– git add master-merge-tw.txt
– git commit -m “add master-merge-tw.txt”
– Merge “twm-branch” to master branch:
– git merge twm-branch
– Check master logs for fast forward merge:
– git log --oneline --graph –decorate
– Delete “ffm-branch” branch:
– git branch -d twm-branch
Lab 3- Resolving Conflict
DevOps course by Abdul Rahim
You will first create a branch and then edit an already existing
file, next you will switch to master branch and edit the same file
in a way that both changes conflict with each other.
– Create a new branch and checkout:
– git checkout -b conflict-branch master
– Edit an existing file master-merge-tw.txt on conflict branch and
append Hello World:
– git add master-merge-tw.txt
– git commit -m “modified master-merge-tw.txt”
Lab 3- Resolving Conflict
DevOps course by Abdul Rahim
– Move to master branch
– git checkout master
– Edit an existing file master-merge-tw.txt on master
branch and append Hello:
– git add master-merge-tw.txt
– git commit -m “modified master-merge-tw.txt on master branch”
– Merge “conflict-branch” to master branch:
– git merge conflict
Lab 3- Resolving Conflict
DevOps course by Abdul Rahim
– You will encounter a merge conflict, run the command:
– git status
– Open the file with the conflict “master-merge-tw.txt” and resolve
the conflict. Once conflicts are resolved add and commit file again
– git add master-merge-tw.txt
– git commit -m “conflict resolved master-merge-tw.txt”
– Delete “conflict-branch” branch:
– git branch -d conflict-branch
Rebasing
DevOps course by Abdul Rahim
– Alternative to integrate changes from one branch
to another
– Changes the base of your branch from one commit
to another
– Integrates upstream changes into your branch
– Linear history
– Command: git rebase
Rebasing
DevOps course by Abdul Rahim
Rebasing vs Merging
DevOps course by Abdul Rahim
– Rebase
– Streamlines a potentially complex history.
– Avoids merge commit “noise” in busy repos with busy branches.
– Cleans intermediate commits by making them a single commit, which can be
helpful for DevOps teams.
– Merge
– Simple and familiar.
– Preserves complete history and chronological order.
– Maintains the context of the branch.
LAB - REBASING
DevOps course by Abdul Rahim
– You will first create a new branch “rebase-branch”.
– Next add a file “rebase-file.txt” commit to “rebase-branch”.
– Switch to master branch.
– Now edit an existing file “master-merge-tw.txt” on master branch,
– Switch back to new branch and then rebase: git rebase
– This will move the base of your branch from earlier commit to
current master branch commit.
Stashing
DevOps course by Abdul Rahim
– Why do we need Stashing?
– Saves you uncommitted code for later use
– Reverts changes from your working copy
– You can make changes, create new commits, switch branches, and
– perform any other Git operations and then re-apply your stash when
– you're ready
– Local to your Git Repo
Stashing Commands
DevOps course by Abdul Rahim
– List Stashes: git stash list
– Stash Changes: git stash
– Apply Stash: git stash apply or git stash pop
– Clear all Stashes: git stash clear
– Stash with description: git stash save "message"
LAB - Stashing
DevOps course by Abdul Rahim
1. Stash Changes
2. Apply Stashed changes
LAB 1 – Stash Changes
DevOps course by Abdul Rahim
– You will create a branch and move into it
– git branch stash-example
– git checkout stash-example
– Now make some changes and check state of working
directory
– git status
– Now stash your changes
– git stash
LAB 1 – Stash Changes
DevOps course by Abdul Rahim
– To see stash changes run the command
– git stash list
– Check state of working directory
– git status
– After stashing the changes your working directory will be clean
LAB 2 – Apply Stashed
changes
DevOps course by Abdul Rahim
– You will reapply your stashed changes
– Check state of working directory
– git status
– Reapply your stashed changes:
– git stash pop
– Check state of working directory
– git status
– You will see the changes you stashed earlier
Tagging
DevOps course by Abdul Rahim
– Allows you to give commit a name
– Mark important checkpoint in the project
– Tags
– Annotated: extra metadata e.g. tagger name, email, and date.
– Lightweight: only tag name
– Branch that doesn’t change
– You can checkout to them
Tagging Commands
DevOps course by Abdul Rahim
– List tags: git tag -l
– Lightweight tag: git tag
– Annotated tag: git tag -a -m
– Tag Details: git show
– Delete tag: git tag --delete
LAB - Tagging
DevOps course by Abdul Rahim
1. Create Lightweight & Annotated Tag
2. List Tags
3. Tag Old Commit
4. Get Information On a Tag
5. Delete Tags
LAB 1- Create Lightweight
& Annotated Tag
DevOps course by Abdul Rahim
– Create lightweight tag on latest commit:
git tag "first-tag“
– Create annotated tag with message on latest commit:
git tag -a "second-tag" -m "tag-test"
LAB 2- List Tag
DevOps course by Abdul Rahim
– List tags using commands:
git tag -l
– You will see the list of tags i.g. ?rst-tag and second-tag
LAB 3- Tag Old Commit
DevOps course by Abdul Rahim
– List old commit:
git log –n3
– This will show list of last three commits
– Copy the hash of second last commit and tag it using the
command:
git tag "third-tag"
LAB 4- Get Information On
a Tag
DevOps course by Abdul Rahim
– Get information on a lightweight tag:
git show first-tag
– Get information on an annotated tag:
git show second-tag
LAB 5- Delete Tags
DevOps course by Abdul Rahim
– Delete all the created tags:
git tag --delete first-tag
git tag --delete second-tag
git tag --delete third-tag
Pull Request
DevOps course by Abdul Rahim
– Method of submitting contribution
– Makes collaboration easier
– Workflow
– Create Branch
– Make Changes
– Create Pull Request
– Merge Once Approved
Lab - Pull Request
DevOps course by Abdul Rahim
– You will first create a new branch “pull-request-branch”.
– Next add a file “pull-request-file.txt” commit to “pull-request-
branch”.
– Now push changes to repository “pull-request-branch” branch.
– You will create a Pull Request from pull-request-branch to master
branch. Create a pull request for Github repository page and click
on "Pull Request" button in the repo header
Forking
DevOps course by Abdul Rahim
– Copy of a repository
– Server-side copy as compared to clone
– Allows to freely experiment without affecting the original
project
– Use Cases
– Propose changes to someone else's project
– Contribute to open source projects
Lab - Forking
DevOps course by Abdul Rahim
– You will fork a repository from GitHub this will create your server-side copy of
repository, then you will clone repository, then make changes and push them to
your copy of remote repository
– On GitHub, navigate to the hello repository. In the top-right corner of the page,
click Fork
– On GitHub, navigate to your fork copy. Under repository name click code
button, and copying the link. Go to the git bash and run clone command.
– Create, add, and commit and push a new file.
– Now create a pull request by using your branch of forked repo.
Contribute to Open Source
Projects
DevOps course by Abdul Rahim
– Fork the Project
– Clone your copy of Project
– Create an upstream remote and sync local copy
– Do the work
– Push to your remote repository
– Create a new Pull Request in GitHub
– Review by Maintainers
– Respond to any code review feedback
Best Practices
DevOps course by Abdul Rahim
– Don't commit directly to master
– Create .gitignore file for your projects
– Don't store credentials as code/config in GitHub
– Write meaningful commit message
– Test Your Code Before You Commit
– Use Branches
– Always pull the latest updates
– Protect your project
– The more approvals, the better
– Rebase your branches periodically
– Agree on workflow
Git PlayGround
DevOps course by Abdul Rahim
– http://git-school.github.io/visualizing-git/
– https://learngitbranching.js.org/?NODEMO
– https://learngitbranching.js.org/
Reference
DevOps course by Abdul Rahim
– https://docs.microsoft.com/en-us/azure/devops/repos/git/git-branching-
guidance?view=azure-devops
– https://www.w3docs.com/learn-git/git-rebase.html
– https://www.git-
tower.com/learn/git/glossary/rebase/#:~:text=In%20Git%2C%20the%20rebase
%20command,straight%2C%20linear%20succession%20of%20commits.

More Related Content

What's hot (20)

PDF
JavaOne 2016 - Pipeline as code
Bert Jan Schrijver
 
PDF
Git Started With Git
Nick Quaranto
 
PPT
Totalsvn Usage And Administration By Gopi
gopinathkarangula
 
PDF
Intro to Git and GitHub
Matthew McCullough
 
PPT
Introduction to Subversion and Google Project Hosting
Philip Johnson
 
PPTX
Jenkins days workshop pipelines - Eric Long
ericlongtx
 
ODP
Svn Basic Tutorial
Marco Pivetta
 
PPTX
Git - Basic Crash Course
Nilay Binjola
 
PDF
Using a Private Git Server for Packaging Software
Chris Jean
 
PDF
Github - Git Training Slides: Foundations
Lee Hanxue
 
PPT
Subversion client
rchakra
 
PDF
Git and github 101
Senthilkumar Gopal
 
PDF
Git 101: Git and GitHub for Beginners
HubSpot
 
PPTX
7 Habits of Highly Effective Jenkins Users
Jules Pierre-Louis
 
PPTX
GIT presentation
Naim Latifi
 
PDF
7 Habits of Highly Effective Jenkins Users
Jules Pierre-Louis
 
PDF
Git Tutorial I
Jim Yeh
 
PPT
Introduction to Git Commands and Concepts
Carl Brown
 
PDF
Git training v10
Skander Hamza
 
PPTX
Git tutorial
Pham Quy (Jack)
 
JavaOne 2016 - Pipeline as code
Bert Jan Schrijver
 
Git Started With Git
Nick Quaranto
 
Totalsvn Usage And Administration By Gopi
gopinathkarangula
 
Intro to Git and GitHub
Matthew McCullough
 
Introduction to Subversion and Google Project Hosting
Philip Johnson
 
Jenkins days workshop pipelines - Eric Long
ericlongtx
 
Svn Basic Tutorial
Marco Pivetta
 
Git - Basic Crash Course
Nilay Binjola
 
Using a Private Git Server for Packaging Software
Chris Jean
 
Github - Git Training Slides: Foundations
Lee Hanxue
 
Subversion client
rchakra
 
Git and github 101
Senthilkumar Gopal
 
Git 101: Git and GitHub for Beginners
HubSpot
 
7 Habits of Highly Effective Jenkins Users
Jules Pierre-Louis
 
GIT presentation
Naim Latifi
 
7 Habits of Highly Effective Jenkins Users
Jules Pierre-Louis
 
Git Tutorial I
Jim Yeh
 
Introduction to Git Commands and Concepts
Carl Brown
 
Git training v10
Skander Hamza
 
Git tutorial
Pham Quy (Jack)
 

Similar to Version control Git -Lecture-2 (20)

PPTX
Git Branching and Merging.pptx
tapanvyas11
 
PPTX
Techoalien git
Aditya Tiwari
 
PPTX
Techoalien git
Aditya Tiwari
 
PPTX
Techoalien git
Aditya Tiwari
 
PPTX
Git tips
Arthur Shvetsov
 
PPTX
Mastering git - Workflow
Tahsin Abrar
 
PPTX
Git
Parag Gupta
 
PPTX
Git workshop
Mateusz Galazyn
 
PPTX
MakingGitWorkForYou
Kwen Peterson
 
PPTX
Git Repository for Developers working in Various Locations
Ganesh Bhosale
 
PPTX
Git tutorial git branches 20131206-Bryan
LearningTech
 
PPTX
Git Best Practices.pptx
ArchanaVaidya15
 
PDF
Git basics a starter on git and its ecosystem
François D'Agostini
 
PDF
devops-complete-notes-2.pdf
RobinRohit2
 
PPTX
Git presentation bixlabs
Bixlabs
 
PPTX
Git One Day Training Notes
glen_a_smith
 
PDF
Git
Mayank Patel
 
PDF
Professional Git 1st Edition Brent Laster
javaleheico
 
PPTX
Git and Github
Teodora Ahkozidou
 
PPT
3 Git
Fabio Fumarola
 
Git Branching and Merging.pptx
tapanvyas11
 
Techoalien git
Aditya Tiwari
 
Techoalien git
Aditya Tiwari
 
Techoalien git
Aditya Tiwari
 
Git tips
Arthur Shvetsov
 
Mastering git - Workflow
Tahsin Abrar
 
Git workshop
Mateusz Galazyn
 
MakingGitWorkForYou
Kwen Peterson
 
Git Repository for Developers working in Various Locations
Ganesh Bhosale
 
Git tutorial git branches 20131206-Bryan
LearningTech
 
Git Best Practices.pptx
ArchanaVaidya15
 
Git basics a starter on git and its ecosystem
François D'Agostini
 
devops-complete-notes-2.pdf
RobinRohit2
 
Git presentation bixlabs
Bixlabs
 
Git One Day Training Notes
glen_a_smith
 
Professional Git 1st Edition Brent Laster
javaleheico
 
Git and Github
Teodora Ahkozidou
 
Ad

Recently uploaded (20)

PDF
July Patch Tuesday
Ivanti
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
PPTX
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
July Patch Tuesday
Ivanti
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
Top Managed Service Providers in Los Angeles
Captain IT
 
Building and Operating a Private Cloud with CloudStack and LINBIT CloudStack ...
ShapeBlue
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Empowering Cloud Providers with Apache CloudStack and Stackbill
ShapeBlue
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Ad

Version control Git -Lecture-2

  • 2. Basic Git Commands DevOps course by Abdul Rahim git --version git init git merge git config --list git add <options> git rebase git config --help git rm/mv <options> git push git config --global git commit <options> git pull git log git diff git checkout git status git reset git fetch git stash git branch git add origin git stash apply
  • 3. Git Branching Strategy / Workflow DevOps course by Abdul Rahim Build your strategy from these three concepts: – Use feature branches for all new features and bug fixes. – Merge feature branches into the main branch using pull requests. – Keep a high quality, up-to-date main branch.
  • 4. Git Branching Strategy / Workflow DevOps course by Abdul Rahim
  • 5. Git Branching DevOps course by Abdul Rahim – Independent/isolated line of development – Inexpensive/lightweight as compared to other VCS – Way to work on different version of a repository – Work in parallel – Master is the default branch – Branches are just pointers to commits – Protected branches
  • 7. Git Branching Commands DevOps course by Abdul Rahim – List Branches: git branch – List all Branches: git branch -a – Create Branch: git branch [branch_name] – Delete Branch: git branch -d [branch_name] – Delete remote Branch: git push origin --delete [branch_name] – Create Branch and Switch: git checkout -b [branch_name] – Switch Branch: git checkout [branch_name]
  • 8. LAB - Branching DevOps course by Abdul Rahim 1. Create Branch 2. List Branches 3. Switch Branch 4. Commit to new Branch 5. Rename Branch 6. Delete Branch
  • 9. LAB 1- Create Branch DevOps course by Abdul Rahim – Create a new branch called “test-branch” by using the command: git branch test-branch
  • 10. LAB 2- List Branch DevOps course by Abdul Rahim – List local branches by using the command: – git branch OR git branch --list – List remote branches by using the command: – git branch -r – List all branches by using the command: – git branch -a
  • 11. LAB 3- Switch Branch DevOps course by Abdul Rahim – In order to commit to new branch, first you will have to switch to newly created branch, using the command: git branch test-branch – To know about current branch run the command: git status
  • 12. LAB 4- Commit to New Branch DevOps course by Abdul Rahim – You have already switched to testing branch. Next create a file “test-branch.txt” in new branch and commit by using the command: git add test-branch.txt git commit -m "create test-branch.txt file for test-branch"
  • 13. LAB 5- Rename Branch DevOps course by Abdul Rahim – Rename the “test-branch” branch to “new-test- branch” using the command: git branch -m test-branch new-test-branch
  • 14. LAB 6- Delete Branch DevOps course by Abdul Rahim – In order to delete the branch first you will have to switch to another branch i.e. master in this case. git checkout master – Delete the “new-test-branch” branch using the command: git branch -d new-test-branch
  • 15. Git Merging DevOps course by Abdul Rahim
  • 16. Git Merging DevOps course by Abdul Rahim – Combine multiple branches into one – Combines multiple sequence into unified history – Commands – Merge branch into active branch: git merge [branch-name] – Merge branch into target branch: git merge [source-branch] [target- branch]
  • 17. MERGING - FAST FORWARD DevOps course by Abdul Rahim
  • 18. MERGING – 3 Way DevOps course by Abdul Rahim
  • 19. MERGING – Resolving Conflict DevOps course by Abdul Rahim
  • 20. LAB - Merging DevOps course by Abdul Rahim 1. Fast Forward merge 2. Three way (3 Way) Merge 3. Resolving Conflict
  • 21. Lab 1- Fast Forward Merge DevOps course by Abdul Rahim You will first create a new branch and then add commit to it and then merge new branch to master branch. – Create a new branch and checkout: – git checkout -b ffm-branch – Create a new file, add, and commit to branch: – git add merge-ff.txt – git commit -m “add merge-ff.txt”
  • 22. Lab 1- Fast Forward Merge DevOps course by Abdul Rahim – Merge “ffm-branch” to master branch: – git checkout master – git merge ffm-branch – Check master logs for fast forward merge: – git log --oneline --graph –decorate – Delete “ffm-branch” branch: – git branch -d ffm-branch
  • 23. Lab 2- Three Way Merge DevOps course by Abdul Rahim – You will first create a branch, then make a commit to it, then switch to master branch and make a commit to it so that it moves ahead from where the new branch was created, then merge new branch to master. – Create a new branch and checkout: – git checkout -b twm-branch master – Create a new file, add, and commit to branch: – git add merge-tw.txt – git commit -m “add merge-tw.txt”
  • 24. Lab 2- Three Way Merge DevOps course by Abdul Rahim – Move to master branch – git checkout master – Create a new file, add, and commit to branch: – git add master-merge-tw.txt – git commit -m “add master-merge-tw.txt” – Merge “twm-branch” to master branch: – git merge twm-branch – Check master logs for fast forward merge: – git log --oneline --graph –decorate – Delete “ffm-branch” branch: – git branch -d twm-branch
  • 25. Lab 3- Resolving Conflict DevOps course by Abdul Rahim You will first create a branch and then edit an already existing file, next you will switch to master branch and edit the same file in a way that both changes conflict with each other. – Create a new branch and checkout: – git checkout -b conflict-branch master – Edit an existing file master-merge-tw.txt on conflict branch and append Hello World: – git add master-merge-tw.txt – git commit -m “modified master-merge-tw.txt”
  • 26. Lab 3- Resolving Conflict DevOps course by Abdul Rahim – Move to master branch – git checkout master – Edit an existing file master-merge-tw.txt on master branch and append Hello: – git add master-merge-tw.txt – git commit -m “modified master-merge-tw.txt on master branch” – Merge “conflict-branch” to master branch: – git merge conflict
  • 27. Lab 3- Resolving Conflict DevOps course by Abdul Rahim – You will encounter a merge conflict, run the command: – git status – Open the file with the conflict “master-merge-tw.txt” and resolve the conflict. Once conflicts are resolved add and commit file again – git add master-merge-tw.txt – git commit -m “conflict resolved master-merge-tw.txt” – Delete “conflict-branch” branch: – git branch -d conflict-branch
  • 28. Rebasing DevOps course by Abdul Rahim – Alternative to integrate changes from one branch to another – Changes the base of your branch from one commit to another – Integrates upstream changes into your branch – Linear history – Command: git rebase
  • 30. Rebasing vs Merging DevOps course by Abdul Rahim – Rebase – Streamlines a potentially complex history. – Avoids merge commit “noise” in busy repos with busy branches. – Cleans intermediate commits by making them a single commit, which can be helpful for DevOps teams. – Merge – Simple and familiar. – Preserves complete history and chronological order. – Maintains the context of the branch.
  • 31. LAB - REBASING DevOps course by Abdul Rahim – You will first create a new branch “rebase-branch”. – Next add a file “rebase-file.txt” commit to “rebase-branch”. – Switch to master branch. – Now edit an existing file “master-merge-tw.txt” on master branch, – Switch back to new branch and then rebase: git rebase – This will move the base of your branch from earlier commit to current master branch commit.
  • 32. Stashing DevOps course by Abdul Rahim – Why do we need Stashing? – Saves you uncommitted code for later use – Reverts changes from your working copy – You can make changes, create new commits, switch branches, and – perform any other Git operations and then re-apply your stash when – you're ready – Local to your Git Repo
  • 33. Stashing Commands DevOps course by Abdul Rahim – List Stashes: git stash list – Stash Changes: git stash – Apply Stash: git stash apply or git stash pop – Clear all Stashes: git stash clear – Stash with description: git stash save "message"
  • 34. LAB - Stashing DevOps course by Abdul Rahim 1. Stash Changes 2. Apply Stashed changes
  • 35. LAB 1 – Stash Changes DevOps course by Abdul Rahim – You will create a branch and move into it – git branch stash-example – git checkout stash-example – Now make some changes and check state of working directory – git status – Now stash your changes – git stash
  • 36. LAB 1 – Stash Changes DevOps course by Abdul Rahim – To see stash changes run the command – git stash list – Check state of working directory – git status – After stashing the changes your working directory will be clean
  • 37. LAB 2 – Apply Stashed changes DevOps course by Abdul Rahim – You will reapply your stashed changes – Check state of working directory – git status – Reapply your stashed changes: – git stash pop – Check state of working directory – git status – You will see the changes you stashed earlier
  • 38. Tagging DevOps course by Abdul Rahim – Allows you to give commit a name – Mark important checkpoint in the project – Tags – Annotated: extra metadata e.g. tagger name, email, and date. – Lightweight: only tag name – Branch that doesn’t change – You can checkout to them
  • 39. Tagging Commands DevOps course by Abdul Rahim – List tags: git tag -l – Lightweight tag: git tag – Annotated tag: git tag -a -m – Tag Details: git show – Delete tag: git tag --delete
  • 40. LAB - Tagging DevOps course by Abdul Rahim 1. Create Lightweight & Annotated Tag 2. List Tags 3. Tag Old Commit 4. Get Information On a Tag 5. Delete Tags
  • 41. LAB 1- Create Lightweight & Annotated Tag DevOps course by Abdul Rahim – Create lightweight tag on latest commit: git tag "first-tag“ – Create annotated tag with message on latest commit: git tag -a "second-tag" -m "tag-test"
  • 42. LAB 2- List Tag DevOps course by Abdul Rahim – List tags using commands: git tag -l – You will see the list of tags i.g. ?rst-tag and second-tag
  • 43. LAB 3- Tag Old Commit DevOps course by Abdul Rahim – List old commit: git log –n3 – This will show list of last three commits – Copy the hash of second last commit and tag it using the command: git tag "third-tag"
  • 44. LAB 4- Get Information On a Tag DevOps course by Abdul Rahim – Get information on a lightweight tag: git show first-tag – Get information on an annotated tag: git show second-tag
  • 45. LAB 5- Delete Tags DevOps course by Abdul Rahim – Delete all the created tags: git tag --delete first-tag git tag --delete second-tag git tag --delete third-tag
  • 46. Pull Request DevOps course by Abdul Rahim – Method of submitting contribution – Makes collaboration easier – Workflow – Create Branch – Make Changes – Create Pull Request – Merge Once Approved
  • 47. Lab - Pull Request DevOps course by Abdul Rahim – You will first create a new branch “pull-request-branch”. – Next add a file “pull-request-file.txt” commit to “pull-request- branch”. – Now push changes to repository “pull-request-branch” branch. – You will create a Pull Request from pull-request-branch to master branch. Create a pull request for Github repository page and click on "Pull Request" button in the repo header
  • 48. Forking DevOps course by Abdul Rahim – Copy of a repository – Server-side copy as compared to clone – Allows to freely experiment without affecting the original project – Use Cases – Propose changes to someone else's project – Contribute to open source projects
  • 49. Lab - Forking DevOps course by Abdul Rahim – You will fork a repository from GitHub this will create your server-side copy of repository, then you will clone repository, then make changes and push them to your copy of remote repository – On GitHub, navigate to the hello repository. In the top-right corner of the page, click Fork – On GitHub, navigate to your fork copy. Under repository name click code button, and copying the link. Go to the git bash and run clone command. – Create, add, and commit and push a new file. – Now create a pull request by using your branch of forked repo.
  • 50. Contribute to Open Source Projects DevOps course by Abdul Rahim – Fork the Project – Clone your copy of Project – Create an upstream remote and sync local copy – Do the work – Push to your remote repository – Create a new Pull Request in GitHub – Review by Maintainers – Respond to any code review feedback
  • 51. Best Practices DevOps course by Abdul Rahim – Don't commit directly to master – Create .gitignore file for your projects – Don't store credentials as code/config in GitHub – Write meaningful commit message – Test Your Code Before You Commit – Use Branches – Always pull the latest updates – Protect your project – The more approvals, the better – Rebase your branches periodically – Agree on workflow
  • 52. Git PlayGround DevOps course by Abdul Rahim – http://git-school.github.io/visualizing-git/ – https://learngitbranching.js.org/?NODEMO – https://learngitbranching.js.org/
  • 53. Reference DevOps course by Abdul Rahim – https://docs.microsoft.com/en-us/azure/devops/repos/git/git-branching- guidance?view=azure-devops – https://www.w3docs.com/learn-git/git-rebase.html – https://www.git- tower.com/learn/git/glossary/rebase/#:~:text=In%20Git%2C%20the%20rebase %20command,straight%2C%20linear%20succession%20of%20commits.