Menu

Log in

Sign up

From beginner to master of web design, coding, infrastructure operation, business development and marketing

  • COURSES
  • HTML & CSS Introduction
  • HTML & CSS Coding with AI
  • Linux Introduction
  • Docker Basics
  • Git & GitHub Introduction
  • JavaScript Coding with AI
  • Django Introduction
  • AWS Basics
  • Figma Introduction
  • SEO Tutorial for Beginners
  • SEO with AI
  • OTHERS
  • About
  • Terms of Service
  • Privacy Policy

© 2024 D-Libro. All Rights Reserved

Git & GitHub IntroductionChapter 4. Edit & Commit

Commit Files – git commit

Commit Files – git commit

How to Commit Files with git commit

git commit is the command to register files in your Local Repository. Once the files are registered with the git commit command, you can retrieve the saved version of the set of files anytime.

Commit message

When you commit files, you need to write some messages about the commit. The messages are recorded along with the code. Typically, you describe what changes were made.

When you run the commit command without the "-m" option, which will be explained below, the command line will get into the waiting mode...

Command Line
git commit
hint: Waiting for your editor to close the file...

...while the text editor will open up for adding a commit message.

Git commit message editor

After typing the commit message, save it and close the file.

Text Editor
the first commmit
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Changes to be committed:
# modified: git_practice.html
#

A new commit will be created as shown below.

Command Line
git commit 
[master 0d93dbb] the first commit
 1 file changed, 1 insertion(+), 1 deletion(-)

There are some frequently used short-cut options for this command.

"-m" option

The -m option is used to describe a commit message directly in the command. If you don't use this option, a registered text editor is launched automatically. In that case, you need to write a commit message in the text editor, save it, and close the text editor. The -m option is useful to make the operation quicker.

git commit -m "Fixed Bugs"

"-a" option

Another option frequently used is the -a or --all option. To commit a modified or deleted file, you need to add the status to the Staging Area by running the git add command. The -a or --all option allows you to directly make a commit (skip the Staging Area). This option is not applicable to untracked files. For example, when you create a new file from the last commit, the file needs to be added to the Staging Area by running the git add command.

git commit -a

Combine options

You can use these two options together. For example, if you modify some files to fix a bug and you want to commit the status, you can run the following command.

git commit -a -m "Fixed Bugs"

Or

git commit -am "Fixed Bugs"

IdeaNote: No file path is needed for the git commit command

Another note for the git commit command is that you don't need to specify a file or directory path differently from the git add command. Because the Git system already tracks the files in the Working Tree and Staging Area, the git commit command automatically detects what files need to be committed.

IdeaTips: Git source control in VS Code

VS Code also provides a GUI (Graphic User Interface) for the Git source control feature. Using the feature, you can make commits using the GUI.

After you edit your code, you can make a commit by typing a commit message and pressing the Commit button.

Git commit button in VS Code

Using the Git source control GUI, you can do many other things. See the following link to learn more about the Git source control in VS Code — Using Git source control in VS Code.


You can also learn this topic offline. Click AmazonKindle.

More Topics to Explore

Sorting File Contents with sort Command

sort (Sort File Contents)

How to Merge Using GitHub

Merge Operation Using GitHub

How to Establish GitHub SSH Connection

GitHub SSH Setup

Granting Remote Repository Access on GitHub

Project Initiator – Grant Remote Repository Access to Project Members

How to Create a Local Repository with git init

Project Initiator – Create Local Repository (git init)

Sorting File Contents with sort Command

sort (Sort File Contents)

How to Merge Using GitHub

Merge Operation Using GitHub

How to Establish GitHub SSH Connection

GitHub SSH Setup

Granting Remote Repository Access on GitHub

Project Initiator – Grant Remote Repository Access to Project Members

How to Create a Local Repository with git init

Project Initiator – Create Local Repository (git init)

Tags:

Commit

Git Key Commands

Git & GitHub Introduction
Course Content

Chapter 1. Git & GitHub Overview

What Is Git?

What Is Version Control?

How To Save Versions in Git?

Collaborating on Git & GitHub – Remote Repository

Collaborating on Git & Git Hub – Branch

Git & GitHub Basic Life Cycle

Chapter 2. Git & GitHub Initial Settings

Git & GitHub Initial Settings Overview

Key Tool Preparation (1) – Mac

Key Tool Preparation (2) – Windows

Key Tool Preparation (3) – Linux Remote Server

Git User Settings – git config

Create GitHub Account

GitHub Access Authentication Settings

Generating PAT (Personal Access Token)

GitHub SSH Setup

Chapter 3. Git & GitHub Project Setup

Three Cases in Git & GitHub Project Setup

Git & GitHub Project Setup Overview in Different Cases

Building Remote Collaboration Practice Environment

Project Initiator – Key Steps To Launch Git Project

Project Initiator – Create Local Repository (git init)

Project Initiator – Make the First Commit

Project Initiator – .gitignore File

Project Initiator – Create Remote Repository

Project Initiator – Link Between Remote and Local Repositories (git remote add)

Project Initiator – Upload Local Repository to Remote Repository (git push)

Project Initiator – Grant Remote Repository Access to Project Members

Project Member – Start Project As Collaborator

Project Member – Create Copy of Project Code on Local Computer (git clone)

Non-Member – Start Project With Replica of Existing Repository (Fork)

Fork vs. Clone

Chapter 4. Edit & Commit

Git Regular Workflow – Edit & Commit

Edit and Commit Overview (1)

Add Files to Staging Area – git add

Commit Files – git commit

HEAD and INDEX

Check Status of Working Tree and Staging Area – git status

Check Commit Histories – git log

Check Differences – git diff

Restore Files to Working Tree – git restore

Undo Changes – git reset

Delete Files – git rm

Edit and Commit Overview (2)

Chapter 5. Work With Branches

Git Regular Workflow – Work With Branches

What Is Branch?

Branch Operation Basic Life Cycle

Create Branch and Check Branch Status – Git Branch

Switch Current Branch (1) – Git Checkout

Switch Current Branch (2) – Git Switch

Merge Branches – Git Merge

Fast-Forward Merge

Non-Fast-Forward Merge (No Option)

Non-Fast-Forward Merge (--no-ff Option)

Squash Merge

Rebase Branch – Git Rebase

Managing Conflict

Stash Changes – Git Stash

Chapter 6. Remote Collaboration

Git Regular Workflow – Remote Collaboration

Remote Collaboration Overview

Link With Remote Repository – Git Remote

Upload to Remote Repository – Git Push

Download Remote Repository and Merge to Local Repository – Git Pull

Get Remote Repository Information to Local Repository – Git Fetch

Pull vs. Fetch

Request for Review and Merge – Pull Request

Merge Operation Using GitHub

Chapter 7. Supplemental Topics

Git Key Commands and GitHub Key Features

Git & GitHub Glossary

GitHub Other Features

Chapter 1. Git & GitHub Overview

What Is Git?

What Is Version Control?

How To Save Versions in Git?

Collaborating on Git & GitHub – Remote Repository

Collaborating on Git & Git Hub – Branch

Git & GitHub Basic Life Cycle

Chapter 2. Git & GitHub Initial Settings

Git & GitHub Initial Settings Overview

Key Tool Preparation (1) – Mac

Key Tool Preparation (2) – Windows

Key Tool Preparation (3) – Linux Remote Server

Git User Settings – git config

Create GitHub Account

GitHub Access Authentication Settings

Generating PAT (Personal Access Token)

GitHub SSH Setup

Chapter 3. Git & GitHub Project Setup

Three Cases in Git & GitHub Project Setup

Git & GitHub Project Setup Overview in Different Cases

Building Remote Collaboration Practice Environment

Project Initiator – Key Steps To Launch Git Project

Project Initiator – Create Local Repository (git init)

Project Initiator – Make the First Commit

Project Initiator – .gitignore File

Project Initiator – Create Remote Repository

Project Initiator – Link Between Remote and Local Repositories (git remote add)

Project Initiator – Upload Local Repository to Remote Repository (git push)

Project Initiator – Grant Remote Repository Access to Project Members

Project Member – Start Project As Collaborator

Project Member – Create Copy of Project Code on Local Computer (git clone)

Non-Member – Start Project With Replica of Existing Repository (Fork)

Fork vs. Clone

Chapter 4. Edit & Commit

Git Regular Workflow – Edit & Commit

Edit and Commit Overview (1)

Add Files to Staging Area – git add

Commit Files – git commit

HEAD and INDEX

Check Status of Working Tree and Staging Area – git status

Check Commit Histories – git log

Check Differences – git diff

Restore Files to Working Tree – git restore

Undo Changes – git reset

Delete Files – git rm

Edit and Commit Overview (2)

Chapter 5. Work With Branches

Git Regular Workflow – Work With Branches

What Is Branch?

Branch Operation Basic Life Cycle

Create Branch and Check Branch Status – Git Branch

Switch Current Branch (1) – Git Checkout

Switch Current Branch (2) – Git Switch

Merge Branches – Git Merge

Fast-Forward Merge

Non-Fast-Forward Merge (No Option)

Non-Fast-Forward Merge (--no-ff Option)

Squash Merge

Rebase Branch – Git Rebase

Managing Conflict

Stash Changes – Git Stash

Chapter 6. Remote Collaboration

Git Regular Workflow – Remote Collaboration

Remote Collaboration Overview

Link With Remote Repository – Git Remote

Upload to Remote Repository – Git Push

Download Remote Repository and Merge to Local Repository – Git Pull

Get Remote Repository Information to Local Repository – Git Fetch

Pull vs. Fetch

Request for Review and Merge – Pull Request

Merge Operation Using GitHub

Chapter 7. Supplemental Topics

Git Key Commands and GitHub Key Features

Git & GitHub Glossary

GitHub Other Features