Git and GitHub - The Complete Guides - Chapter 1 (Git Basics)
Tags: webdev, beginners, github, git
Published: 2021-08-30 21:44:01

![goran greets](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4y9d2njam1i41zo0i298.png)

I want to revisit the <strong>git commit</strong> command and a few other things...

In the previous chapter we made a few commits and we learned how to check the history of commits using <strong>git log</strong> commands. 

There is a <em><strong>different way</strong></em> of making commits. First we need to make some changes to our existing files from the previous chapter. <em>"You can make whatever changes you want in the index.html file or style.css file"</em>.

After making the changes and saving, we can check the current status by using <strong>git status</strong>, as expected we will see that our file/files have not been staged for a commit. We can set them to the staged status by using the <strong>git add</strong> command, when we have staged the file/files and <em>check the status</em> again, we can see that we have <u><em>files to be committed</em></u>. Awesome!

![git-snapshot](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ipp7t7n9yc3tn55cwmly.png)

Now to see how to do a <strong>git commit</strong> in a different way. To do this we type only <strong>git commit</strong> and when we press enter, a new file will be opened in our text editor. This is because we set Visual Studio Code as our default text editor when we installed Git. This file is called <strong>COMMIT_EDITMSG</strong> and it contains a few comments.

We can add our <strong>git commit</strong> message inside this file just like we do in the terminal. You will notice the terminal says <em>"Waiting for your editor to close the file"</em>, all we need to do is add our message to the <strong>COMMIT_EDITMSG</strong> file, save and close it then we will see the terminal has recognised we added our <strong>git commit</strong> message.

![alternative-git-commit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ffelizn26t3drel4g0wd.gif)

We can check the short version of the history of our commits using <strong>git log --oneline</strong> and see that our commit has been captured by git. 

What do you think will happen if <strong>VS-CODE</strong> is not our default text editor, well we can check this by unsetting it as our default text editor inside a file called <strong>.gitconfig</strong>. The <strong>.gitconfig</strong> file contains some configuration settings of our project, like our username and email as well as our branch name, but more on that later. 
To open the .gitconfig file in the text editor we use the command: <strong>code ~/.gitconfig</strong>

<blockquote>The ~ (tilde) sign allows us to navigate to the folder of the user </blockquote>

![git-editor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d2h8b03rox5brjk2wbj1.gif)

<blockquote>You should know that the <strong>.gitconfig</strong> file is not located in the project folder, it is located in the user directory because it is a global file and it has access to every git repository. That's why we use the <strong>--global</strong> flag with the <strong>git config</strong> command</blockquote>

As you can see at the bottom of the <strong>.gitconfig</strong> file, the <code><strong>[core] 
editor = code --wait</strong></code>. All we need to do is remove this from the <strong>.gitconfig file</strong> and this will <u>unset</u> <strong>VS-CODE</strong> as our default text editor.

But a more professional way of doing this is by running the following command: <strong>git config --global --unset core.editor</strong>, after running it the <code><strong>[core] editor = code --wait</strong></code> will be removed from the <strong>.gitconfig</strong> file.

![git-.gitconfig](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/933fozm0y48p8r5aoa93.gif)

Time to make a commit. However first we have to make modifications to the file/files in our project directory. Once we make the changes and save, as usual we set the file to the staging area by running the <strong>git add</strong> command. Finally we can run our <strong>git commit</strong> command.

![Anticipation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p70v78kdy39ekhmmnn0h.gif)

When we run the <strong>git commit</strong> command, we will get a new screen on our terminal, actually this is a default git editor called <strong>VIM</strong>. You can see there are some comments and like the terminal we are able to insert our message for the <strong>git commit</strong> command.

To work with <strong>VIM</strong> is a little out of the scope of this extended chapter. But for those who want to get familiar with <strong>VIM</strong>, you can explore the cheat sheet here: <a href="https://vim.rtorr.com/">VIM Cheat Sheet</a>

In short, to insert a message while inside the VIM editor:
<ul>
<li>Press <strong>i</strong> - (This means insert)</li>
<li>Press ESC - (after entering the comment, to get out of edit mode)</li>
<li>Press :wq - (to save and quit)</li>
</ul>
 
![VIM-editor](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/av02g1zelgofwewx6n2f.gif)

As we can see after we saved and quit, the commit runs successfully and we can check this by running the command: <strong>git log --oneline</strong>.

To set <strong>VS_CODE</strong> as our default editor again we need to run the following command: <strong>git config --global core.editor "code --wait"</strong>. This will add the previously removed text back into the <strong>.gitconfig</strong> file.

![default-vs-code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/134kw6po0wkpyfl43ubj.gif)

When you first setup Git and run the <strong>git init</strong> command, you may come across a message:
 
<code><em>"Using 'master' as the name for the initial branch. This default branch name is subject to change. To configure the initial branch name to use in all of your new repositories, which will suppress this warning, call:"</em></code>. 

As stated, this message can be suppressed by running the command: <strong>git config --global init.defaultBranch</strong>, this command is followed by the name you wish to give your branch.
For example: <strong>git config --global init.defaultBranch Branch1</strong>

Finally we can list all the configuration settings in our <strong>.gitconfig</strong> file by running the command: <strong>git config --list</strong>.

![git-list](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09ofx3kg36s7os214yjk.gif)

Cool stuff, after this Extended chapter, I think we are ready to move on to Chapter 2. I hope you enjoyed.

![moving on](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ce1u45rxxi5coz8urouq.gif)