Git: What are the Basic Commands and Uses?

Git Create

The Git command is written and compiled briefly as the following command.

When we initialize, the subdirectory structure for git in the folder is created.

Looking at the Situation

Looking at the state of our repository is often something we have to do. We give information about the repo and we understand what to do depending on the situation.

Repository Cloning

Copying a repository is one of the simplest procedures. The only condition is that the destination folder does not exist or is an empty folder. (some users delete the contents, even if they are folders, etc. This is a separate issue, but we will talk through Git SCM)

As a repository URL, for example, when you enter a repository in Github, we will use the link that appears under the button Clone or Download:

clone with SSH
clone with SSH

It is not compulsory to write the name of a folder, but it will help you to learn.

For example;

this way. You may receive an error if you have not set the SSH Key.

Adding Files to Repository

Adding and committing files is two separate cases, and even uploading up (to the server) is a separate process. If we need to follow this step by step, we need to do this in order to add, commit and upload files.

Adding Files

We can also use the add command to add files to the repository.

For example;

While we are in the root directory of our repository, we can add it as follows:

For example;

Commit Files

By adding, we make changes, added, deleted files, etc. We have prepared for our commit. Now it’s time for us to commit. Commit to process our process. So; I added this file, I deleted this file, we call it updated.

While commit, we also need to write a message, the reason we write it is not necessary to know what we have added to delete what we do not need to write very unnecessary notes so that the commit can be seen what has changed. For example; # 123. bug fixed we can write. Here we added a file to be considered, we do not need to write a long message such as file b deleted, you can examine here for example. Since only 1 file has been modified in the commit detail in the example, you can only see the changes of that file, but by looking at the different reports, we can see what commit is done.

Above we have made a single-line example.

-m can write our message directly. Alternatively, we could write our message like vim by saying   git commit  directly and write down the change in detail.

Push Commit (s)

This is a step we also call pushing, throwing up. We have edited and deleted files, as well as throwing changes into the main repository.

example;

Getting the Current Report from Remote Repo

To get the latest update from the remote repository, we will first perform fetch, then pull.

Fetch

Fetch brings us only the status of the last updated version. So this has changed, we see reports like this has changed. We will also use the pull command to get the changes.

example;

If we have not given any name, the default name is given to our file as “origin”.

Pull

Pull means pull. We’ve received the changes, now we can take our file. If you pull without fetch, you pull the last version of the fetch.

example;

I hope it has been a useful article.