Git Commit -m “ Basics of git”

Introduction to Git

Akula Hemanth Kumar
3 min readSep 26, 2021
Photo by Roman Synkevych on Unsplash
  1. Commit
  2. Branch
  3. Merge
  4. 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.

Current State

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
Current State

Lets create a Feature branch from head of Master

git branch Feature

Create Feature Branch

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.

Current State

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

Merge Feature into Master

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

Merge master into Feature

Rebase

Applies your branch commits one by one, on top the base branch.

Current State

git rebase Master

Rebase the Feature branch onto Master branch

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:

  1. Merging vs. Rebasing | Atlassian Git Tutorial
  2. 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)
  3. Learn How to Commit to Git: Git Commit Command Explained (bitdegree.org)

--

--