2024-02-19

In this blog you will learn how to stage and commit our changes and files using GIT

Blog post by MF Mabala

Learning GIT

GIT

Git- is a open source distributed version control system that is available for free. The git source code is often hosted on GitHub. To be able to use Git you have to download into your computer. To download Git in windows you can use the following link.

https://git-scm.com/download/win

We will be using the command prompt that is in our windows machine .To locate the the command prompt . Go to your windows search bar and type Command Prompt and click on it to open .

To see if git has been installed you will check the version using :

git --version

Creating your local Git Repository

You need to create a folder in your computer and name it what you want I will name mine example-demo .Use the following commands to initialize an empty git repository to your folder.

cd example-demo
git init

Go into your code editor: VSCODE in this case. Open the folder you just named and inside the folder create a file named demo.txt. Inside the folder right any text you would like and leave it like that.

Staging and committing your code

Committing code- This is the process where our code is added to our local repository so that we can add it to our GitHub repository. when writing code you have commit each change you make to your code. Before we can commit our changes or files the code that we add has to be in the staging area first. If you do not add your code to the staging area you wont be able to commit it.

Staging

To stage your file (demo.txt) use the following command in your command prompt

git add demo.txt

Committing

Now your file/files are ready to be committed . With each commit you have to add a commit message that is relevant to what you have committed. The message is written in the inverted commas . This helps you track what all your commits were about. Use the following command commit files and changes .

git commit -m "Initial Commit

You can check the status of your files. You will see if there are files that are not yet staged and need to be stage . You will see the files that are staged and need to be committed . Use the following command to check the status.

git status

To see all your commits you can use the following command

git log

OR

git log --all --graph

This is all for staging and committing files using git. In the next blog we will learn more about using git when writing code as a developer.

Thank you for reading my blog.