Today we will learn how to configure Git with Debian 11. Consider a scenario where multiple developers are working on the same project. How to keep control of a different version of their work? Git is the answer! it’s one of the most famous version control of today.
Git was originally developed by Linus in 2005. Git is designed for such developers who just need nothing but a straightforward version control system.
What is a version control system? Well, you can assume it as a centralized repo. Where are developers can work on the same project or on a module/part of the project? Without affecting other team member’s work they can keep contributing.
Developers can keep their work intact in form of branches. In branches, developers can develop, stage, and commit their codes.
How to configure git with Debian 11.
Prerequisites? Basic knowledge of Linux, a Debian 11 machine, 4 GB RAM, and 40 GB storage will be sufficient.
Update server first.
# apt update
Install git on your Debian server.
# apt install git
Check what version of Git is installed.
# git --version
Next, git requires to set config, where you provide Name and Email id.
Define user name
# git config --global user.name "Rajneesh Kumar"
Define email id.
# git config --global user.email "firstname.lastname@example.org"
Confirm for changes updates.
# git config --list
All of the git configurations are stored under the gitconfig file. The file is stored as hidden in the home directory.
Have a look.
# ls .gitconfig
One more command can be used to define parameters.
# git config --global --edit
amend your settings here.
Basic git adminstration
Now installation part is over, let’s see how to configure git basic commands.
Create a new project.
# mkdir newgit
Change to that directory.
# cd newgit/
Make this folder a new git repo for your project.
# git init
Now, this folder is initiated for the git project.
A new .git directory is created under /newgit folder. Let’s have a look.
# cd .git/ && ls
Git status can be checked by following the command.
# git status
There is no file created yet, and git code committed. Let’s create a program first.
# vim test.sh
#!/bin/bash echo "Hello World"
Add file to git.
# git add test.sh
Check the status again.
# git status
Now we can see clearly that the file is added to git. The file is moved to the staging area. The staging area is nothing but a hold stage where the program is kept before coming to the final project.
Comming your file from the staging area. With git commit command -m option we use to make a comment for reference. Comment helps another contributor to understand what changed you have made.
# git commit -m "unixcop repo"
To check how many coming you have made till now, use the following command. A unique id gets generate for each log. All details like which author commit at what time are visible.
# git log
Create few more files and commit all of them at once. I created two files named with unixcop1.sh and unixcop2.sh.
# git status
We can see there are multiple files that are not added to the git stage. Let’s add all files to the git stage at once. use git add with dot (.) option. Check the status again.
# git add .
Commit again and check log.
# git commit -m "testing 2.0"
Now, we can see two commit id are generated here.
We can switch to any commit stage.
Copy the desired commit id, use with checkout option.
# git checkout 6c98d648ff830824d4d2d2e21d62350ff6b01c8f
Now list the directory and you will see the only test.sh file, because at that time only test.sh file was created.
This is how git can be managed using different commands. Stay tuned for the next article.