Push
Commit
Local Repository
(.git repo)
origin
Working Directory
Pull
Pull
Stash Tags are objects used to label specific points in
the commit history of a repository
Provide a way to reference specific commits
Frequently used to mark software release
versions (v1.0,v1.1,v2.0 etc.)
- Lightweight and Annotated
Two Types
Clone
Creates a local copy of the entire repository
- Files ,Commit History ,Branches and Tags
Cloning is done from an existing remote
repository
- Usually called origin
- Permissions are required
Repo URL required
- Can be obtained from the hosting platform
Local Repository
(.git repo)
origin
Clone
Working Directory
Fork
Copy of a Repository
Changes can be merged back into original
repository using pull requests
Does not impact the original repository which
is commonly referred as upstream repo
Used for contributing code to a repository
where you are not an authorized contributor
Commonly used in open source projects
Clone vs Fork
Use Clone to make a local copy of an existing repository
Use Fork to make a copy of the repository on GitHub
Both are used to create a copy of an existing repository
On GitHub, once you create a Fork of a repository ,you have your own
public copy of the repository in GitHub.
Post Fork creation , to work with the code, you need a local copy so you
have to make Clone of the Fork. Once you clone, you have a local repo on
your computer which is configured with a remote repo named Origin on
GitHub.
Fork Overview
GitHub
Local Computer
Public Repo Forked Repo
Fork
Local Repo
(origin)
Clone
GitHub
Fork Overview
GitHub
Local Computer
Public Repo Forked Repo
Local Repo
(origin)
Local Repo
{Bug Fix}
Forked Repo
{Bug Fix}
Pull Request
Public Repo
{Bug Fix}
Tags
Tags are objects used to mark or label specific
commit in the commit history of a repository so
that you can refer them in future
Frequently used to mark software release
versions (v1.0,v1.1,v2.0 etc.)
For example, you can tag a commit that
corresponds to a release version, instead of
creating a branch to capture a release
snapshot.
- Lightweight and Annotated
Two Types
V 1.0
Types of Tags
- Lightweight Tags : Points to a specific commit, includes tag name
- Annotated Tags : Points to a specific commit and includes metadata
such as tag name ,tagger name ,message ,date
Main
Development
V 1.0
Main
Development
V 1.0
Resetting to commit in GitHub Desktop
Branch
Reverting a commit in GitHub Desktop
Branch
Discarding changes in GitHub Desktop
Discarded files are moved to Trash/Recycle Bin
You can discard all uncommitted changes in one or more files
If you have uncommitted changes that you don't want to keep,
you can discard the changes.
You can discard changes in one or more lines
Undoing a commit in GitHub Desktop
Useful if you made a mistake in the changes you included.
Not possible if you have already pushed the commit to the remote
repository.
Restores the changes from a commit to working directory,
so you can make further changes before re-committing.
Resetting to commit in GitHub Desktop
Allows set your local history back to your latest pushed
commit/non-local commit
It resets the HEAD of the repo to the commit you selected, keeping all the
changes in the working directory and in the commits in between.
Reset to Commit allows for discarding more than one
commit at a time
Amending a commit in GitHub Desktop
Helpful in scenarios like edit the commit message or including/excluding
changes in the commit
Replaces the previous commit with a new commit to the current branch
It is way to modify the most recent commit you have
made in your current branch
Ideally you should only amend a commit that you haven't pushed to the
remote repository.
To amend a commit that has been pushed to the remote repository, you will
need to use a force push to overwrite the commit history in the remote
repository.
Reordering commits in GitHub Desktop
To reorder commits which are already pushed to remote branch ,force
push is required.
Reordering allows to alter a branch’s commit history to provide a more
meaningful progression of commits
Reverting a commit in GitHub Desktop
When you revert to a previous commit, the revert is also a commit. The
original commit also remains in the repository's history.
You can revert a specific commit to remove its changes from your
branch
When you revert multiple commits, it's best to revert in order from
newest to oldest. If you revert commits in a different order, you may see
merge conflicts.
Three options of Git Reset
Working Directory
Staging Area
(Index)
.git Directory
(Repository)
git reset --soft
git reset --mixed
git reset --hard
Three options of Git Reset
Working Directory
Staging Area
(Index)
.git Directory
(Repository)
git reset --soft
git reset --mixed
git reset --hard
Cherry Pick Cherry pick enables us to choose a commit or
specific commits from one branch and apply it
to another branch
Cherry pick is advanced feature
- Should not be considered as an alternative
of merge
Creates copy of a commit – conceptually
similar to copy and paste
- Can cause confusion
MERGE CHERRY PICK REBASE
Cherry pick to a Feature Branch
Feature Branch
Change 1
Change 2
Cherry-pick to Version Branches
4.0
3.1
2.5
Cherry-Picking a Hotfix to a Release Branch
1 2
Main Branch
Hotfix Branch
Release Branch
3
Fix
2
Fix
Fix
Cherry Pick
Cherry Pick
Rebase Conflict
Main Branch
Feature 2 Branch
Feature 1 Branch
Merge Conflict
Main Branch
Feature 2 Branch
Feature 1 Branch
Common Reasons/Situations for Merge Conflict
Line Change Merge Conflict
- When one developer deletes a file but another developer edits the same
content and tries to merge the change to the same branch
File Merge Conflict
- When more than one developer changes the same line in
a file and tries to merge the change to the same branch
- When one developer deletes the content in a file but another developer
edits the same content and tries to merge the change to the same
branch
Occurs when there are conflicting changes
Line Change Merge Conflict
Main Branch
Feature 2 Branch
Feature 1 Branch
Same line got
changed in the same
file
Line Change Merge Conflict
Main Branch Feature 2 Branch
<<<<<<< HEAD
"""Adds two numbers"""
return x + y
==========
"""Adds two numbers. Added logging."""
print(f"Adding {x} and {y}")
return x + y
>>>>>>> Feature 2
This is the changed code in Main branch
Separator for other file content
Changed code in the Feature 2 branch
Resolve the conflict and commit
"""Adds two numbers. Added logging."""
print(f"Adding {x} and {y}")
return x + y
Merge Conflict Resolution
Line Change Merge Conflict
Conflict
- Git resolves most differences by itself
- Git needs you to decide how to merge/combine
File markers indicate conflicting changes
Edit the file to combine the content
Finally perform commit (merge commit)
- Review the <<<<< and >>>>> markers
File Merge Conflict
Main Branch
Feature 2 Branch
Feature 1 Branch
Add file with same
name but different
content
Types of File Merge Conflict
Add/add
File with same name added in both
branches but the content is different
Rename/rename
A file is renamed under different
names in two branches
Rename/delete
A file is renamed in one branch and
deleted in another
Modify/delete
A file is modified in one branch but
same file is deleted in another branch
What is a Pull Request
Main or
Development
Branch
Branch for
Feature /
Issue
Request for reviewing the code
and merge the changes to target
(main / development) branch
Pull Request
Why is it called Pull Request ?
git merge
git fetch
git pull
Pull Request is a process
Create
Raise a Pull Request
Review
Reviewer performs
the review and
provides feedback
Approve
If everything looks fine,
code is merged
into the target branch
Rebase Scenarios
Pull without merge
Pull changes from other
branch to your branch
Clean up of history
Cleaning up your local history
before sharing a branch
Merge Conflict
So what is a merge conflict and how do they
happen?
It updates the base of the current branch
(typically feature) by replaying its commits on
top of the latest commits from the other branch
(typically main or master)
Rebase
Rebase is used to integrate changes from one
branch onto another branch
It updates the base of the current branch
(typically feature) by replaying its commits on
top of the latest commits from the other branch
(typically main or master)
Never use Rebase on a branch which is shared with other
developers
Use Rebase carefully !!
As Rebase alters the history of the branch ,in case other
developers are working ,it would be causing merge
conflicts and inconsistency in the codebase.
Rebasing and then force-pushing (git push --force) can
overwrite others' changes if they have pushed commits to
the same branch.
Rebase
master
feature
M1
M2
M2
F1
M3
F2
M2
Rebase
master
feature
M1
M2
F1
M3
F2
Rebase
master
M1
M2
M3
feature
F1
F2
Squash Commits
1 2 3
1
3
2
4
4
Squash Commits
main
solution/feature
Merge
Combine changes from one branch to
another
- Takes commits from source branch
Combine history of one branch into another
- Integrates into the target branch
How features and bug fixes are added
Supported Merge Strategies
3-Way Merge
or
Standard Merge
or
True Merge
Fast forward Merge
Fast forward
Merge
Special type of merge
- Branch being merged has no additional
commits since the branching point
The head/branch pointer of the target
branch is moved to the latest commit of the
source branch
Causes the target branch to “fast forward”
Fast forward Merge
master
feature
M1
M2
M2
F1 F2
Fast forward Merge
master
feature
M1
M2
M2
F1 F2
F1 F2
F1 F2
3-Way Merge
Both of the branches have diverged. Meaning
both having additional commits since the
branching point.
3-Way Merge use a dedicated commit (i.e.
merge commit ) to tie together the two commit
histories.
Git uses three commits to generate the merge
commit: the two branch tips and their
common ancestor.
3-Way Merge
master
feature
M1
M2
M2
F1
M3
3-Way Merge
master
feature
M1
M2
M2
F1
M3
M3
F1
M2 M
merge commit
Rebase
master
feature
M1
M2
M2
F1
M3
Branch
Default branch is main or master
Independent development line of work
Each branch has its own commit history
main
feature-1
feature-2
Branch
Branches isolate your development work
from other branches in the repository
- Allows working on different features or bugs
without affecting the main codebase
Developers can create new branches
- Part of their daily workflow
Changes made on one branch
- Do not affect other branches
- Until they are merged
What We Would Do with Branches ?
❏ Create a new branch
❏ Create a branch from a previous commit
❏ Publish a branch to remote
❏ Compare branches
❏ Choose a branch and make few changes
❏ Rename a branch
❏ Delete a branch
Type of Branches
❏ Local Branch
❏ Remote (tracking) Branch
Local Branches
- A local branch exists only on your local machine.
- When you create a new branch in GitHub Desktop, you're creating
a local branch. This branch is a copy of your code that you can
work on independently.
- Any changes you make to local branch are saved locally,
meaning they won't be visible to others until you push the branch
to a remote repository.
Remote (tracking) Branches
- Remote tracking branches are basically local branches that have a
special connection to a branch on a remote repository ,such as
GitHub.
- When you clone a repository, GitHub Desktop automatically
creates remote tracking branches that mirror the branches on the
remote.
- Remote tracking branches are used for collaboration and staying
synchronized
Clone
Local Repository
(.git repo)
origin
Clone
Working Directory
Branch and Merge
Local Repository
(.git repo)
origin
Working Directory
Fetch
Merge
What Can We Do with Branches ?
❏ Publish branches
❏ Commit into branches
❏ Merge branches
❏ Compare branches
❏ Rename or delete branches
❏ Rebase branches
Branch
main
feature-1
feature-2
feature-3
Branch
main
feature-1
feature-2
Push
Commit
● Switch to Repo
● Initial Commit bottom left
Working Directory Local Repository
(.git repo)
Stage
sample-git-project
Commit Each commit contains
- Snapshot of files
- Commit message
- Author and timestamp
- Unique Identifier
Snapshot of a repository at one point in time
Working
Directory
Stage .git Directory
The Three Sections of a Git Project
The project folder/directory
for your project files
Prepare Commits Stores the entire history of
your project (contains Commit
history, staging area,
branches, configuration etc. )
Checkout
Stage
Commit
The Three States of Files
Modified or
Untracked
Staged Committed
Modified
or
Untracked
Modified
- Changed since last commit
Untracked
- Not yet committed
Git detects changes by comparing current state
of the file with version in repo
Staged These files are added to Index
- Also known as Staging Area
An entire file can be staged
- Or only a specific portion
Process of marking files to be included in the
Commit
Committed
- Commit becomes part of repo’s History
Represents files that have been added
permanently to the repository
Setting up GitHub Desktop
Configure Git for GitHub Desktop
Install GitHub Desktop
Install Git
git config --global user.name “GitHub User name"
git config --global user.email “GitHub Email"
Clone
Node.js is a open source and cross-platform runtime environment for JavaScript .
It allows JavaScript to be run outside of a browser, enabling server-side scripting.
npm (Node Package Manager) is bundled with Node.js and is the package
manager for Node.js packages
Install Node.js
Install VS Code
Install Java 8
Install Maven
Install Intellij IDEA CE
Create and Run
Sample Maven based
project in Intellij
Install Java 8
Install Maven
Install Eclipse IDE
Create and Run
Sample Maven based
project in Eclipse
Node.js is a open source and cross-platform runtime environment
for JavaScript . It allows JavaScript to be run outside of a browser,
enabling server-side scripting.
npm (Node Package Manager) is bundled with Node.js and is the
package manager for Node.js packages
- Used to install ,manage and share JavaScript packages
- Handles dependency management
Why "npx create-react-app <app_name> " command looks for the
location "C:Users<username>AppDataRoamingnpm " ?
create-react-app is an npm package
The location "C:Users<username>AppDataRoamingnpm" is the
directory for globally installed npm packages
If create-react-app is already globally installed, npx will use the global
installation
If create-react-app is not globally installed, npx will temporarily install and
run it
Install Node.js
Install VS Code
Create a React App
npx create-react-app hello-world
Architect
Developer1 Developer2
Architect
Developer1
Developer2
main
development
feature/logging
feature/validation
Stash
After stashing changes on a branch, you can
safely change branches or make other
changes to your current branch
If you have saved changes that you are not
ready to commit yet, you can stash the
changes for later.
Stash - The changes are temporarily removed from
the files
When you stash changes
- You can choose to restore or discard the
changes later.
Stashes are local operation , they are not
pushed
You can only stash one per branch at a time
with GitHub Desktop
Fork
Fork is used to create a copy of a repository in
GitHub
Changes can be merged back into original
repository using pull requests
Does not impact the original repository which
is commonly referred as upstream repo
Used for contributing code to a repository
where you are not an authorized contributor
Commonly used in open source projects
Clone vs Fork
Use Clone to make a local copy of an existing repository
Use Fork to make a copy of the repository on GitHub
Both are used to create a copy of an existing repository
On GitHub, once you create a Fork of a repository ,you have your own
public copy of the repository in GitHub.
Post Fork creation , to work with the code, you need a local copy so you
have to make Clone of the Fork. Once you clone, you have a local repo on
your computer which is configured with a remote repo named Origin on
GitHub.
Fork Overview
GitHub
Local Computer
Public Repo Forked Repo
Fork
Local Repo
(origin)
Clone
Upstream Repo Origin Repo
Fork Overview
GitHub
Local Computer
Public Repo Forked Repo
Local Repo
(origin)
Local Repo
{Bug Fix}
Forked Repo
{Bug Fix}
Pull Request
Public Repo
{Bug Fix}
Upstream Repo Origin Repo
Syncing with parent repository
GitHub
Local Computer
Public Repo
v 225
Forked Repo
v 152
Local Repo
v 152
Upstream Repo Origin Repo
Working Directory
Staging Area
(Index)
.git Directory
(Repository)
Merge vs Rebase
Key differences between Merge and Rebase
- Get changes from a feature branch back into
the main branch
- Update feature branches with changes from main
branch
When to use which one for our workflow
Scenario 1 : Incorporating
changes from Feature to Main
C
0
main
C
1
A B C
C
0
main
C
1
A B C
D E
feature
feature
Fast Forward Merge
3-way Merge
C
0
main
C
1
A B C
C
0
main
C
1
A B C
D E
feature
feature
M
Fast Forward Merge
3-way Merge
Scenario 2 : Incorporating
changes from Main to Feature
Merg
e
C
0
main
C
1
A B C
D E
feature M
C
0
main
C
1
A B C
D E
feature
Rebase
A’ B’ C’
C
0
main
C
1
D
A
B
C
featur
e
Remot
e
C
0
C
1
D
A
B
C
featur
e
Local
main
A’
B’
C’
Scenario 1 : Incorporating
changes from Feature to Main
Merg
e
C
0
main
C
1
A B C
D E
feature
M
C
0
main
C
1
A B C
D E
feature Rebase
??
main
Merg
e
C
0
C
1
A B C
D E
feature
M
C
0
main
C
1
A B C
D E
feature
Rebase and FF
Merge
A’ B’ C’

GitHub+Desktop+Slides udemy______________

  • 2.
  • 3.
  • 4.
  • 5.
    Stash Tags areobjects used to label specific points in the commit history of a repository Provide a way to reference specific commits Frequently used to mark software release versions (v1.0,v1.1,v2.0 etc.) - Lightweight and Annotated Two Types
  • 6.
    Clone Creates a localcopy of the entire repository - Files ,Commit History ,Branches and Tags Cloning is done from an existing remote repository - Usually called origin - Permissions are required Repo URL required - Can be obtained from the hosting platform
  • 7.
  • 8.
    Fork Copy of aRepository Changes can be merged back into original repository using pull requests Does not impact the original repository which is commonly referred as upstream repo Used for contributing code to a repository where you are not an authorized contributor Commonly used in open source projects
  • 9.
    Clone vs Fork UseClone to make a local copy of an existing repository Use Fork to make a copy of the repository on GitHub Both are used to create a copy of an existing repository On GitHub, once you create a Fork of a repository ,you have your own public copy of the repository in GitHub. Post Fork creation , to work with the code, you need a local copy so you have to make Clone of the Fork. Once you clone, you have a local repo on your computer which is configured with a remote repo named Origin on GitHub.
  • 10.
    Fork Overview GitHub Local Computer PublicRepo Forked Repo Fork Local Repo (origin) Clone GitHub
  • 11.
    Fork Overview GitHub Local Computer PublicRepo Forked Repo Local Repo (origin) Local Repo {Bug Fix} Forked Repo {Bug Fix} Pull Request Public Repo {Bug Fix}
  • 12.
    Tags Tags are objectsused to mark or label specific commit in the commit history of a repository so that you can refer them in future Frequently used to mark software release versions (v1.0,v1.1,v2.0 etc.) For example, you can tag a commit that corresponds to a release version, instead of creating a branch to capture a release snapshot. - Lightweight and Annotated Two Types V 1.0
  • 13.
    Types of Tags -Lightweight Tags : Points to a specific commit, includes tag name - Annotated Tags : Points to a specific commit and includes metadata such as tag name ,tagger name ,message ,date Main Development V 1.0
  • 14.
  • 15.
    Resetting to commitin GitHub Desktop Branch
  • 16.
    Reverting a commitin GitHub Desktop Branch
  • 17.
    Discarding changes inGitHub Desktop Discarded files are moved to Trash/Recycle Bin You can discard all uncommitted changes in one or more files If you have uncommitted changes that you don't want to keep, you can discard the changes. You can discard changes in one or more lines
  • 18.
    Undoing a commitin GitHub Desktop Useful if you made a mistake in the changes you included. Not possible if you have already pushed the commit to the remote repository. Restores the changes from a commit to working directory, so you can make further changes before re-committing.
  • 19.
    Resetting to commitin GitHub Desktop Allows set your local history back to your latest pushed commit/non-local commit It resets the HEAD of the repo to the commit you selected, keeping all the changes in the working directory and in the commits in between. Reset to Commit allows for discarding more than one commit at a time
  • 20.
    Amending a commitin GitHub Desktop Helpful in scenarios like edit the commit message or including/excluding changes in the commit Replaces the previous commit with a new commit to the current branch It is way to modify the most recent commit you have made in your current branch Ideally you should only amend a commit that you haven't pushed to the remote repository. To amend a commit that has been pushed to the remote repository, you will need to use a force push to overwrite the commit history in the remote repository.
  • 21.
    Reordering commits inGitHub Desktop To reorder commits which are already pushed to remote branch ,force push is required. Reordering allows to alter a branch’s commit history to provide a more meaningful progression of commits
  • 22.
    Reverting a commitin GitHub Desktop When you revert to a previous commit, the revert is also a commit. The original commit also remains in the repository's history. You can revert a specific commit to remove its changes from your branch When you revert multiple commits, it's best to revert in order from newest to oldest. If you revert commits in a different order, you may see merge conflicts.
  • 23.
    Three options ofGit Reset Working Directory Staging Area (Index) .git Directory (Repository) git reset --soft git reset --mixed git reset --hard
  • 24.
    Three options ofGit Reset Working Directory Staging Area (Index) .git Directory (Repository) git reset --soft git reset --mixed git reset --hard
  • 25.
    Cherry Pick Cherrypick enables us to choose a commit or specific commits from one branch and apply it to another branch Cherry pick is advanced feature - Should not be considered as an alternative of merge Creates copy of a commit – conceptually similar to copy and paste - Can cause confusion
  • 26.
  • 27.
    Cherry pick toa Feature Branch Feature Branch Change 1 Change 2
  • 28.
    Cherry-pick to VersionBranches 4.0 3.1 2.5
  • 29.
    Cherry-Picking a Hotfixto a Release Branch 1 2 Main Branch Hotfix Branch Release Branch 3 Fix 2 Fix Fix Cherry Pick Cherry Pick
  • 30.
    Rebase Conflict Main Branch Feature2 Branch Feature 1 Branch
  • 31.
    Merge Conflict Main Branch Feature2 Branch Feature 1 Branch
  • 32.
    Common Reasons/Situations forMerge Conflict Line Change Merge Conflict - When one developer deletes a file but another developer edits the same content and tries to merge the change to the same branch File Merge Conflict - When more than one developer changes the same line in a file and tries to merge the change to the same branch - When one developer deletes the content in a file but another developer edits the same content and tries to merge the change to the same branch Occurs when there are conflicting changes
  • 33.
    Line Change MergeConflict Main Branch Feature 2 Branch Feature 1 Branch Same line got changed in the same file
  • 34.
    Line Change MergeConflict Main Branch Feature 2 Branch
  • 35.
    <<<<<<< HEAD """Adds twonumbers""" return x + y ========== """Adds two numbers. Added logging.""" print(f"Adding {x} and {y}") return x + y >>>>>>> Feature 2 This is the changed code in Main branch Separator for other file content Changed code in the Feature 2 branch Resolve the conflict and commit """Adds two numbers. Added logging.""" print(f"Adding {x} and {y}") return x + y
  • 36.
    Merge Conflict Resolution LineChange Merge Conflict Conflict - Git resolves most differences by itself - Git needs you to decide how to merge/combine File markers indicate conflicting changes Edit the file to combine the content Finally perform commit (merge commit) - Review the <<<<< and >>>>> markers
  • 37.
    File Merge Conflict MainBranch Feature 2 Branch Feature 1 Branch Add file with same name but different content
  • 38.
    Types of FileMerge Conflict Add/add File with same name added in both branches but the content is different Rename/rename A file is renamed under different names in two branches Rename/delete A file is renamed in one branch and deleted in another Modify/delete A file is modified in one branch but same file is deleted in another branch
  • 39.
    What is aPull Request Main or Development Branch Branch for Feature / Issue Request for reviewing the code and merge the changes to target (main / development) branch Pull Request
  • 40.
    Why is itcalled Pull Request ? git merge git fetch git pull
  • 41.
    Pull Request isa process Create Raise a Pull Request Review Reviewer performs the review and provides feedback Approve If everything looks fine, code is merged into the target branch
  • 42.
    Rebase Scenarios Pull withoutmerge Pull changes from other branch to your branch Clean up of history Cleaning up your local history before sharing a branch
  • 43.
    Merge Conflict So whatis a merge conflict and how do they happen? It updates the base of the current branch (typically feature) by replaying its commits on top of the latest commits from the other branch (typically main or master)
  • 44.
    Rebase Rebase is usedto integrate changes from one branch onto another branch It updates the base of the current branch (typically feature) by replaying its commits on top of the latest commits from the other branch (typically main or master)
  • 45.
    Never use Rebaseon a branch which is shared with other developers Use Rebase carefully !! As Rebase alters the history of the branch ,in case other developers are working ,it would be causing merge conflicts and inconsistency in the codebase. Rebasing and then force-pushing (git push --force) can overwrite others' changes if they have pushed commits to the same branch.
  • 46.
  • 47.
  • 48.
  • 49.
    Squash Commits 1 23 1 3 2 4 4
  • 50.
  • 51.
    Merge Combine changes fromone branch to another - Takes commits from source branch Combine history of one branch into another - Integrates into the target branch How features and bug fixes are added
  • 52.
    Supported Merge Strategies 3-WayMerge or Standard Merge or True Merge Fast forward Merge
  • 53.
    Fast forward Merge Special typeof merge - Branch being merged has no additional commits since the branching point The head/branch pointer of the target branch is moved to the latest commit of the source branch Causes the target branch to “fast forward”
  • 54.
  • 55.
  • 56.
    3-Way Merge Both ofthe branches have diverged. Meaning both having additional commits since the branching point. 3-Way Merge use a dedicated commit (i.e. merge commit ) to tie together the two commit histories. Git uses three commits to generate the merge commit: the two branch tips and their common ancestor.
  • 57.
  • 58.
  • 59.
  • 60.
    Branch Default branch ismain or master Independent development line of work Each branch has its own commit history main feature-1 feature-2
  • 61.
    Branch Branches isolate yourdevelopment work from other branches in the repository - Allows working on different features or bugs without affecting the main codebase Developers can create new branches - Part of their daily workflow Changes made on one branch - Do not affect other branches - Until they are merged
  • 62.
    What We WouldDo with Branches ? ❏ Create a new branch ❏ Create a branch from a previous commit ❏ Publish a branch to remote ❏ Compare branches ❏ Choose a branch and make few changes ❏ Rename a branch ❏ Delete a branch
  • 63.
    Type of Branches ❏Local Branch ❏ Remote (tracking) Branch
  • 64.
    Local Branches - Alocal branch exists only on your local machine. - When you create a new branch in GitHub Desktop, you're creating a local branch. This branch is a copy of your code that you can work on independently. - Any changes you make to local branch are saved locally, meaning they won't be visible to others until you push the branch to a remote repository.
  • 65.
    Remote (tracking) Branches -Remote tracking branches are basically local branches that have a special connection to a branch on a remote repository ,such as GitHub. - When you clone a repository, GitHub Desktop automatically creates remote tracking branches that mirror the branches on the remote. - Remote tracking branches are used for collaboration and staying synchronized
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
    What Can WeDo with Branches ? ❏ Publish branches ❏ Commit into branches ❏ Merge branches ❏ Compare branches ❏ Rename or delete branches ❏ Rebase branches
  • 71.
  • 72.
  • 73.
  • 74.
    ● Switch toRepo ● Initial Commit bottom left
  • 75.
    Working Directory LocalRepository (.git repo) Stage sample-git-project
  • 76.
    Commit Each commitcontains - Snapshot of files - Commit message - Author and timestamp - Unique Identifier Snapshot of a repository at one point in time
  • 77.
    Working Directory Stage .git Directory TheThree Sections of a Git Project The project folder/directory for your project files Prepare Commits Stores the entire history of your project (contains Commit history, staging area, branches, configuration etc. ) Checkout Stage Commit
  • 78.
    The Three Statesof Files Modified or Untracked Staged Committed
  • 79.
    Modified or Untracked Modified - Changed sincelast commit Untracked - Not yet committed Git detects changes by comparing current state of the file with version in repo
  • 80.
    Staged These filesare added to Index - Also known as Staging Area An entire file can be staged - Or only a specific portion Process of marking files to be included in the Commit
  • 81.
    Committed - Commit becomespart of repo’s History Represents files that have been added permanently to the repository
  • 82.
    Setting up GitHubDesktop Configure Git for GitHub Desktop Install GitHub Desktop Install Git git config --global user.name “GitHub User name" git config --global user.email “GitHub Email" Clone
  • 83.
    Node.js is aopen source and cross-platform runtime environment for JavaScript . It allows JavaScript to be run outside of a browser, enabling server-side scripting. npm (Node Package Manager) is bundled with Node.js and is the package manager for Node.js packages
  • 84.
  • 85.
    Install Java 8 InstallMaven Install Intellij IDEA CE Create and Run Sample Maven based project in Intellij
  • 86.
    Install Java 8 InstallMaven Install Eclipse IDE Create and Run Sample Maven based project in Eclipse
  • 87.
    Node.js is aopen source and cross-platform runtime environment for JavaScript . It allows JavaScript to be run outside of a browser, enabling server-side scripting. npm (Node Package Manager) is bundled with Node.js and is the package manager for Node.js packages - Used to install ,manage and share JavaScript packages - Handles dependency management
  • 88.
    Why "npx create-react-app<app_name> " command looks for the location "C:Users<username>AppDataRoamingnpm " ? create-react-app is an npm package The location "C:Users<username>AppDataRoamingnpm" is the directory for globally installed npm packages If create-react-app is already globally installed, npx will use the global installation If create-react-app is not globally installed, npx will temporarily install and run it
  • 89.
    Install Node.js Install VSCode Create a React App npx create-react-app hello-world
  • 90.
  • 91.
  • 92.
  • 93.
    Stash After stashing changeson a branch, you can safely change branches or make other changes to your current branch If you have saved changes that you are not ready to commit yet, you can stash the changes for later.
  • 94.
    Stash - Thechanges are temporarily removed from the files When you stash changes - You can choose to restore or discard the changes later. Stashes are local operation , they are not pushed You can only stash one per branch at a time with GitHub Desktop
  • 95.
    Fork Fork is usedto create a copy of a repository in GitHub Changes can be merged back into original repository using pull requests Does not impact the original repository which is commonly referred as upstream repo Used for contributing code to a repository where you are not an authorized contributor Commonly used in open source projects
  • 96.
    Clone vs Fork UseClone to make a local copy of an existing repository Use Fork to make a copy of the repository on GitHub Both are used to create a copy of an existing repository On GitHub, once you create a Fork of a repository ,you have your own public copy of the repository in GitHub. Post Fork creation , to work with the code, you need a local copy so you have to make Clone of the Fork. Once you clone, you have a local repo on your computer which is configured with a remote repo named Origin on GitHub.
  • 97.
    Fork Overview GitHub Local Computer PublicRepo Forked Repo Fork Local Repo (origin) Clone Upstream Repo Origin Repo
  • 98.
    Fork Overview GitHub Local Computer PublicRepo Forked Repo Local Repo (origin) Local Repo {Bug Fix} Forked Repo {Bug Fix} Pull Request Public Repo {Bug Fix} Upstream Repo Origin Repo
  • 99.
    Syncing with parentrepository GitHub Local Computer Public Repo v 225 Forked Repo v 152 Local Repo v 152 Upstream Repo Origin Repo
  • 100.
  • 101.
    Merge vs Rebase Keydifferences between Merge and Rebase - Get changes from a feature branch back into the main branch - Update feature branches with changes from main branch When to use which one for our workflow
  • 102.
    Scenario 1 :Incorporating changes from Feature to Main
  • 103.
    C 0 main C 1 A B C C 0 main C 1 AB C D E feature feature Fast Forward Merge 3-way Merge
  • 104.
    C 0 main C 1 A B C C 0 main C 1 AB C D E feature feature M Fast Forward Merge 3-way Merge
  • 105.
    Scenario 2 :Incorporating changes from Main to Feature
  • 106.
    Merg e C 0 main C 1 A B C DE feature M C 0 main C 1 A B C D E feature Rebase A’ B’ C’
  • 107.
  • 108.
    Scenario 1 :Incorporating changes from Feature to Main
  • 109.
    Merg e C 0 main C 1 A B C DE feature M C 0 main C 1 A B C D E feature Rebase ??
  • 110.
    main Merg e C 0 C 1 A B C DE feature M C 0 main C 1 A B C D E feature Rebase and FF Merge A’ B’ C’