Git Flow
learn programming

Git Flow

Are you writing code but not using a version control system? This is probably worse than writing a thesis without saving a document every 10-15 minutes. Of course, you can, but why this extra work when something goes wrong?

In this article, I will present the easiest way to use the version control system for my own use. This will be an overview of the most used, at least by me, functionalities of Git. It is worth mentioning that Git is not the only version control system, but it is certainly very popular and easy to use. In the set with Git, I also use GitHub, which is also not the only option. So much for the introduction. I invite you to read the article.

Git installation

Depending on the system, the installation will run a bit differently, but it is certainly not complicated. On Linux systems, the installation is done with the command sudo apt-get install git.

In the system, Windows download the installation file from the site https://git-scm.com/ and install Git using the built-in installer. I have no idea how Installing Git looks like on MacOS.

git logo
Git logo

It is worth paying attention to one element during installation,
so as not to have a heart attack later. The default editor for git is VIM (bane for beginners).

However, you can choose a different editor during installation, e.g. Nano (for Linux), Notepad ++ (for Windows) or just your code editor (if is on the list). The remaining installation elements can be left as they are if we don’t want to delve into them at first.

Some trainers recommend installing terminal extensions to speed up the entry of Git commands. I personally found a much easier and in my opinion faster solution.

I use VS Code to write the code, which has a built-in extension to support the version control system. It works great and is good enough for basic operations.

I perform custom operations in the console, but not often enough to bother configuring terminal plugins. It is true that I tried to use these extensions, but in Windows this task turned out to be quite troublesome.

After installing git, we get the option to run the Git console. In the beginning, it’s a good idea to add your user name and email address to the git. In the Git Bash console, we issue the following commands:

Git config –global user.name FirstName LastName

Git config –global user.email your@email.adress

The global switch sets the entered data as the default for each project. They can be changed to other ones in a specific project.

GitHub

We already have a local version of git that we can run in any directory with the git init command. The coolest option, however, is that you can set up a remote repository to have independent access to it from different machines.

git hub logo
Git hub logo

What’s more, it is a great backup of the projects we are working on. As I mentioned in the introduction, GitHub is not the only place where you can keep a repository.

I don’t even mean other GitLab services, because Dropbox is also great for keeping a repo outside the machine. For this article, however, I’d like to focus on GitHub.

Creating an account on github.com is free. After creating an account, it’s time to configure communication between GitHub and your local Git.

For beginners, it’s a good idea to set up a test repo on GitHub and then clone it to your local machine. To do this, after creating a repo on GitHub, click the “Clone or download” button and a link to copy will appear. Now go to Git bash on our machine and type git clone / link from github /

Git will copy the repo to your disk, but will first ask for login credentials. This is exactly what we meant. After entering the login and password, git will connect to the remote repo and download it, but more importantly, windows will remember our password and from now on we will be able to download the repo, work on it and send changes to Git Hub using the git push command

Basic Git commands for everyday use:

Git clone – this is a command that allows you to copy the repository directly from the remote repo.

Git add – adds a file with the changes made to the “temporary memory” that can be persisted using the git commit command.

Git commit – allows you to save the state of the repository at the moment. It is based on what we added to the temporary state with the git add command.

Git push – allows you to send the state of our local repository to a remote repository.

Git pull – pulls changes made on the remote repo to our local repo.

Git fix – allows you to “merge” two commits into one, when you want to fix something in an already sent commit, or we forgot to add something to a sent commit.

Summarizing

That’s all it takes to start working with a Git. Of course, you can configure git differently, but isn’t it more about installing Git quickly and getting used to it? In my opinion, it’s good to start with the basics, catch some rhythm of work, and then delve more as needed. I personally discover new possibilities of Git from time to time, and this is precisely because I need something.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

X