Git Commit -m “ Basics of git”
Introduction to Git
- Commit
- Branch
- Merge
- Rebase
Commit
- Generally Commit means saving changes.
- Git does not add changes to a commit automatically. we need to explicitly add the changes to be committed.
git add <file1>,<file2>git commit -m “Commit message”
To know more about Commit checkout Blog in Reference #3.
git commit
A new commit C2 added on Master
branch.
BRANCH
We can Create a new branch from head of base branch using below command
git branch <branch name>
To see the list of branches, we can use
git branch
OR
git branch — list
Lets create a Feature
branch from head of Master
git branch Feature
Created a Feature
branch from Master
branch at commit C2.
Lets try to do a commit.
git commit
This created a new commit (C3) on master because we are on Master branch.
lets create a new commit on Feature Branch.
We need to run below commands
git checkout featuregit commit
git checkout feature
Currently we are on Feature
branch as asterisk (*) is present on it.
Lets create a commit on Feature
branch.
git commit
Merge
Creates a new commit, called a merge commit, with the differences between the two branches.
Currently we are on Master
branch as asterisk (*) is present on it.
we are merging Feature
into Master
. This creates a new merge commit(C5) in the Master
branch.
git merge Feature
Lets merge Master
branch to Feature
branch
git checkout Featuregit merge Master
One liner for above 2 Commands
git merge Feature Master
git checkout Feature
git merge Master
Rebase
Applies your branch commits one by one, on top the base branch.
git rebase Master
The entire Feature
branch Commits are moved to begin on the top of the Master
branch, C4* commit is new commit on top of C3 commit.
git checkout mastergit rebase Feature
git checkout master
git rebase Feature
References:
- Merging vs. Rebasing | Atlassian Git Tutorial
- pcottle/learnGitBranching: An interactive git visualization and tutorial. Aspiring students of git can use this app to educate and challenge themselves towards mastery of git! (github.com)
- Learn How to Commit to Git: Git Commit Command Explained (bitdegree.org)