Git Document
Git Document
Git client 3
Modifying files and pushing those changes to local and remote repositories 4
Working Area: 4
Staging/Index Area: 4
Checking commit history of this branch 5
Checking commit history of a file 5
Pushing local commits to remote repository 5
Git get specific version of a file 5
Git Fetch 5
Git Branch 6
Creating a git branch 6
Switching a branch 6
Merging changes in our branch to main branch 6
Note: --global tells git to use the same information for all the repositories i manage on
my local machine.
Working Area:
Any modifications we do to the local repository those modification are kept under
working area.
Staging/Index Area:
This area is to stage the files we wanna commit to local & remote repository
git status
This provides information about our local repository (working area, stating area & local
repository)
Note: Before we perform commit git name and email must be configured
Git Fetch
Gets remote changes to the local without merging.
g
it fetch origin master
For merging
Git Branch
Branch is used to work on a specific task (enhancement, bug, new feature)
Branch provides isolation, i.e. other work will not impact my work
Master branch: every git repository comes with a default branch which is called as
master branch.
- No one should directly work on master
- Master must contain only well tested code
- In real world most of the guys will not have permissions to push to master
If there is a new task to work on, then we should create a branch and work on it.
Pull Request
Pull request enables team mates to review and comment on the changes before
merging to main branch, we also can see how many file are modified, we also can
compare modified file with their old version.
Fast forward merge move the pointer of master from C3 to C5
Rebase Merge
Undoing commits
- Reset
- Revert
Git reset:
- Removes the commit from the history
Git revert:
It doesn't remove the commit from the history, instead it reverts changes to the files and
makes a new commit.
Note: If commits are already pushed to remote we can't use reset instead we should go
with revert
Git stash
git stash temporarily shelves (or stashes) changes you've made to your working copy so
you can work on something else, and then come back and reapply them later on
Master branch:
Master must contain well tested code, application release happens from this branch by
creating a release ‘tag’.
In real world no one directly work on master.
Hotfixes:
This branch is used for fixing production defects.
Hotfixes branch is created from master
Develop branch:
This branch belongs to a specific team, code integration of this team members are
done on this branch
Develop branch is created from master
Feature branch:
Belongs to a specific developer, where his feature in implemented, after completion of
a feature changes are merged into his develop branch.
Feature branch is created from develop branch
Release branch:
This branch is to integrate changes done by multiple teams under their develop branch
Git tag
In git tag is a pointer pointing to a specific commit, tag is similar to branch but, branch is
used for development/bugfix, whereas tag is used for releasing software.
On a branch we can do commits, but on a tag we cannot perform commits.
Creating a tag
git tag VERSION-1.0.0
Pushing a tag to remote
git push origin VERSION-1.0.0
Delete a tag in local
git tag -d VERSION-1.0.0
Display tags
git tag -d VERSION-1.0.0