Git is one of the concepts that almost everyone who steps into open source and/or free software development has heard in some way. If you have a vision or dream of becoming a developer in these areas, it is not enough that you have heard of Git, you should also know how to use it very well.
In this article, we will simply try to convey the use of Git to you. First of all, there is an important question that needs to be answered, What is Git?
What is Git?
To put it by definition:
Git is a speed-oriented, distributed version control and source code management system used in software development processes. It was originally designed and developed by Linus Torvalds himself in 2005 for use in the development of the Linux kernel. (…)Wikipedia
Let's expand on this definition a little more. It is a system where you can write down every change you make while developing a software step by step, you can easily see the changes made and even return quickly, which makes it easier to work with more than one person on a single project, in short, it provides great benefits to software developers by facilitating version tracking. Git can run in a local repository as well as in remote repositories online or offline. GitHub and GitLab, which are popular today, are among the most used online Git services. GitHub/GitLab and Git should not be confused with each other. Git is a system, GitHub and GitLab are services.
After explaining what Git is above, we can get started. The first thing we need to do is, of course, the installation.
To install Git on your Pardus and other Debian-based Linux distributions, you can open the terminal environment and enter the following command.
sudo apt install git
This command may differ in distributions using other package systems.
After the installation is complete, you can learn the version you have installed by typing the following command.
Introducing your identity to the Git system is one of the first things you should do. Thus, when you look back, it becomes clear who made the changes, which is very important. Let's complete this step by entering the following commands in order.
git config --global user.name "user-name" git config --global user.email "email-address"
git config --global user.name "prdsmehmetstc" git config --global user.email "firstname.lastname@example.org"
First of all, you have to navigate to the directory where you want to use Git via the terminal interface. When using git commands, you should work from the directory you want to work in and should not leave that directory.
After reaching the directory you want, you must enter the following command.
If you look at the directory you are in when entering this command from the file manager, you can see that it is empty, unless you have not checked the show hidden files option. Actually the folder is not empty, there is a folder named .git in it. Now that folder is a “Git Repository”.
You did your work in the folder, that is, in the repository, you created your files. Now it's time to add the files you created by entering the command below to the repository.
As seen in the above command
git add . If you type, all files will be taken to the transition zone. If you only want to import a single file
git add dosyaAdi shaped; if you want to get a directory with its contents
git add dizinAdi You can write.
All the work does not end with the above command, now you need to "commit" the files you have received in the transition zone, that is, to process them into the system. For this, enter the following command.
git commit -m "Comment"
Now the files have been committed to the system. Now let's move on to other useful and must-know commands.
With this command, you can see the commits and see when and what has been done so far.
This command will show you the status of your project. It shows you information such as whether there is a file to commit, if there is a file that has been deleted or not added.
This command will show you a change made to your files line by line. It shows the changes with green color and (+) sign if addition was made, red color and (-) sign if subtraction was made. You have to commit again to apply the changes made. In addition, to see the differences between the transition zone and the warehouse,
git diff --staged command is used.
There are two methods for deleting files in Git. One is manual deletion and the other is using git command.
git rm dosyaAdi If you write the relevant file,
git rm -r dizinAdi/ If you type it, it will delete the relevant directory and its contents. After this process, you need to repeat the commit process.
With this command, you can rename or move files. To change the file name
git mv dosyaAdi yeniDosyaAdi in the form, if for moving files
git mv dosyaAdi dizinAdi/ You can write as. Of course, you should commit again after this process.
Undo changes made
Undoing changes made in Git projects depends on the region where the file is located. Different operations are performed in the transition area and different in the working area.
Rollback in working directory
If you want to undo the change made to a file in the working directory, you must enter the following command.
git checkout -- filename
Rollback in transition zone
If you want to undo the changes made to a file in the transition zone, you must enter the following commands one by one.
git reset HEAD filename git checkout -- filename
If you want to fully revert to a particular commit, you must enter the following command.
git checkout 95a6e33d877afbfe6e43419996cda613bdd4936a -- .
The part marked in bold above is the ID of the relevant commit. this much
git log You can find out with the command If you want to revert only one file in that commit
. Just type the filename instead. After this situation, you need to commit again for the changes to be applied.
If you want to work on GitHub or GitLab instead of working locally, there are a few more things you need to know. for that you to this post let's take. 🙂