Mastering Git and Github: Essential Information (Part 2)

Soumya DeySoumya Dey
4 min read

Introduction

Welcome to the world of Git โ€“ the backbone of modern software development. In this concise guide, we'll explore vital Git commands like git config, git add, and git commit, laying the groundwork for your journey into version control mastery. Let's dive in and uncover the power of Git's core functionalities.


what is git config ?

First of all the git config command refers to git configuration. This configuration lets you personalize how you work on git. This configuration can be done globally, locally and system wide. We will be focusing on the global configuration of git because its the most usable configuration.

  • Setting the user name : we use git config --global user.name "user name" to set the user name globally which will be associated to all the commits that you make any in git repository on your system. The --global flag signifies that the configuration should be made globally, meaning it will affect all the repositories in you system.

  • Setting the user email : we use git config --global user.email "youremail@gmail.com" to set the users email address globally which will be associated to all the commits that you make any in git repository on your system. The --global flag signifies that the configuration should be made globally, meaning it will affect all the repositories in you system.

  • Setting the default code editor : As you work with multiple files, you need to use a code editor to make changes. Visual Studio Code (VS Code) is a widely used editor among developers. The git config --global core.editor "code --wait" command is used to set VS Code as the default editor.


Git init command

After installing Git, it won't automatically track all the files on your system. It's your responsibility to instruct Git to track a specific folder so that any changes made in it can be monitored by Git.

  • Git init : Suppose I have a folder named "project," and I want Git to track changes made in that folder.

To do this, I need to be inside that folder and run the command git init . This command will create a Git repository, indicating that this folder will be tracked by Git. By running this command, an empty Git repository will be generated in that folder, named .git. This folder is crucial as it stores all the essential information about your project.


Git status command

The git status command provides a summary of the current state of the repository. It shows which files have been modified, which files are staged for the next commit, and which files are untracked. This helps users understand what changes have been made and what actions are needed before committing them.


Git add command

The git add command plays a crucial role in the Git workflow by allowing users to stage changes for inclusion in the next commit. When you make modifications to files in your working directory, Git doesn't automatically track or include those changes in the next commit. Instead, you use git add to selectively choose which changes you want to include in the commit.

By staging changes with git add, you're essentially telling Git, "Hey, these are the changes I want to include in the next snapshot of my project." This selective staging capability gives you control over what gets committed, allowing for more organized and focused commits. It's particularly useful when you've made changes across multiple files but only want to commit a subset of those changes.

In essence, git add serves as a tool for fine-tuning your commit history, ensuring that each commit represents a coherent set of changes and contributes meaningfully to the project's development timeline.

The git add . command specifies that all files in the unstaged area should be placed into the staging area.

We can also specify to git which files should be in the staging area by using the command git add <file1> <file2> ..


Git commit command

The git commit command creates a snapshot of the changes staged with git add and saves it to the repository's history. It requires a commit message describing the changes made in the commit. This command is essential for recording progress and keeping track of the project's development.

The command is git commit -m "commit message" . Here the -m flag specify that provide a message.

If you only use git commit command it will open the VS Code editor where you need to provide a commit message to COMMIT_EDITMSG file. After providing a relevant commit message you need to close the file to complete the process

0
Subscribe to my newsletter

Read articles from Soumya Dey directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Soumya Dey
Soumya Dey

๐Ÿ‘‹ Hello! I'm soumya aka persevere, a passionate Full Stack Developer with a flair for crafting innovative and scalable digital solutions. I am also an technical content writer. . . . #FullStackDeveloper #WebDevelopment #JavaScript #React #Nodejs #MongoDB #ProblemSolver #Innovation #Collaboration