What is Git?
Git is a distributed version control system. Version control systems (VCS) are software tools that help software teams manage changes to source code over time. There are many VCS available and Git is one of them, having been developed by Linus Torvalds in 2005. A VCS helps you do the following:
- Have a complete history of changes to your source code as a log.
- Branching and merging of the work on the source code into many streams, allowing various team members to work together parallel to each other at the same time.
- Tracing each change made to the source code. (Developers often use this feature to roll back an update to their code if such a need arises.)
This process is called source code management. I have used the Atlassian guide to learn Git, which I would highly recommend for beginners since it is very well documented and thus is easier to understand.
To install Git on your machine you can use this guide, if you are using any other system than Windows. For Windows:
- Download the latest Git for Windows installer.
- When you’ve successfully started the installer, you should see the Git Setup wizard screen. Follow the Next and Finish prompts to complete the installation. You should be fine with the default settings if you want to immediately get started with Git.
Setting up a repository
Repositories are created in your project’s directory (folders like this –> 📁 in your PC. This is just a pictorial representation, you can have folder icons of many types). There are two ways through which you can get started with Git for your project. This is the place where the different versions of your updated projects are stored.
In short, this is the history book 📓 of your project.
- You can start a Git repository in your project’s directory.
- You can clone an existing project.
For this step you will need PowerShell and a working knowledge with CLI. Working with
cmd.exe is also fine, but I choose PowerShell, here are my reasons. You can also use Git Bash, a Windows app for emulating the Git CLI experience, to execute the commands.
This command is used to configure how you are presented on Git. There are three levels of git configurations, system, global and repository. If you are starting about, you will need these two configurations:
git config --global user.name <your name here>(within "" if there is a space). This will change the Git username so that you can know who made the changes to your project.
git config --global user.email <your email here>This will add your email information to the commits.
For all practicality, you would prefer using the
global settings for most of your commits. But if you want to have a specific name and email associated with a directory, you can do that through the
git config --local user.name/email <info> after opening PowerShell in that specific directory.
This command will initiate a repository in the directory where you execute it. To do so use
cd <directory name> (add the path in between
< >) to navigate to the directory of your project first. Then execute this command.
cd <directory name> git init
Or you can use this command:
git init <project directory> to initialise a Git repository in an existing project.
git init is a one time operation in a project directory, consider it like a notebook that stores the entry of all the people in an office, you only need to have one register.
As the name might have made it clear, this command is used to clone an existing project repository in a remote repository like GitHub and obtain a local development clone. Git is the DVCS and GitHub is a service that hosts repositories for projects.
git clone <repo url>
You can use Git SSH URL to do the same. You can use the link to know more about it if you are interested.
git add <file name> git commit -m "add a message here"
This command is used to add file version changes to your project’s repository and then commit the change with a message attached to it. This way, you will have an idea later why the commit was made. The
add command basically gets your changes ready for being
committed as changes to the remote repository.
These are the basic commands that you need to know if you want to interact with the code of countless programmers out there in places such as Git!
Get git! 🚀