What Is GIT?
Table of contents
INTRODUCTION
Git is a distributed version control system software that is commonly used in software development that allows developers to be able to keep track of changes in their code, communicate with other developers and roll back any change made to the code if necessary. In this article, I will talk about the basics of Git and the steps to using Git on your computer.
What is Git?
As I said earlier, it is an open-source distributed version control system software other popular ones being Mercurial and Bazaar, that allows developers to track, communicate and revert changes made to their codes. This is done by creating a repository where all files relating to the code are stored on the hard drive.
A repository is a directory where your codebase and all its versions are stored. Git tracks every version of the codebase and stores it as a commit. A commit is like a snapshot of the repository at any point in time.
Since it is a distributed version control system (DVCs), each developer working on that code can have a copy of the repository on their individual computers enabling them to make changes to the code without affecting the work of other developers.
How to Use Git
To use git, there are some steps you have to follow:
Step 1: Download and Install Git
The first thing to do before you're able to use it is to install git on your system. You can download it from their website and then follow the prompts to install it on your system. After installing it, you open your command line and type "git version" to confirm if the installation was successful.
The version shows her meaning it is installed on my system
Step 2: Go to the Terminal on your vscode and navigate to the directory
Your terminal can be accessed at the top nav bar of the vs code. There you can create a new terminal.
Then you select the directory you want to access. You can use "cd" to change the directories. But since you're opening it under the folder in vscode, the directory will already be selected.
Step 3: Initialize a Git repository
This is done by using the "git init" command. This creates a new git repository or initializes an old one in your project directory.
You know it is successful after it tells you on your terminal that it has been initialized the the codes will turn green as shown above.
Step 4: Adding files to the repository
When adding files to the repository, you can either add all the files in the current directory by using the "git add ."
Or you can add individual files using "git add <filename>"
Step 5: Checking the state of the repository
After adding files to the repository, you can check to confirm if they were added using the "git status" command. This shows the state of the repository at that point.
These are the files I used the git add command to add.
Step 6: Deleting files from your repository
To do this you use the "git rm --cached <file-name>" command. This removes the file from the repository.
As you can see I removed the style.css file which is why it is labeled as untracked.
Step 7: Commit your changes
As explained earlier, commits are snapshots of the codebase. So to commit your changes you use the command "git commit". This creates a new commit with the changes you've made to the files.
As we can see, the files that were added before have been committed. You'll also be able to give a message.
Conclusion
Git is a powerful tool for managing your codebase and effectively collaborating with others. You can track changes to your codebase with Git, roll back to prior versions, and work independently without affecting others. I hope this article will be able to make you more interested in Git.