Basic git commands for completely beginners

Git is a tool which boosts programmers to really extremely high level. If you think:

Basic git commands for completely beginners

Git is a tool which boosts programmers to really extremely high level. If you think:

I do not need that, I can code normally without version control system

you will probably fail at creating little more complex applications.

From my point of view, if a developer is not capable of creating a new repository, operating on different branches, committing new changes, he will stagnate.

In the university we never used anything for controlling current version of a project. What is more, I am pretty’s sure that the most of lectures never mastered basics of git. That’s one of the proves that:

You don’t need a degree, to land a perfect job

Let’s go quickly through 7 basic commands to start with GIT.

Git init

Git init, like the name indicates, initialize the local repository. It is the very first command to start with.

In the terminal, go to the directory that contains files of a project and run

$ git init

After executing this command, the hidden .git subdirectory will be added in a file structure.


Git clone

The clone command makes a local copy of a concrete online repository, downloads it and save location of a remote source, so that it is possible to push changes and create new pull requests.

$ git clone <git-repo-url>

Git branch

As a beginner developer, it is crucial to know how to create a new branch or delete the wrong one. Eventually it will be useful to know how to rename created branch.

Creating new branch locally:

$ git branch <branch-name>

Deleting a branch

$ git branch -d <branch-name>

Renaming the branch

$ git branch -m <branch-name> <new-branch-name>

Git checkout

This command allows to switch to existing branch or create quickly new one. Remember, you have to commit changes before a checkout process.

Switching to an existing branch

$ git checkout <branch-name>

Create and switch to the new one

$ git checkout -b <new-branch-name>

Git add

Git add command is necessary to save changes in a branch, without adding those differences in a code, it is impossible to commit them. In most of cases, it is sufficient to add every changes to the staging area, by:

$ git add .

But it is also worth to get acquainted with adding specific files.

$ git add <file-name-1> <file-name-2>

Git commit

Finally, git commit, which is in my opinion the crucial command in git. Well organized commits are the very important part of every pull request and extremely helpful in debugging process.

Typing optimal messages and adding concrete changes should be the fundamental part of work in development.

Git commit saves changes in local repository. Every time, it is proceeding, it is necessary to make a quick note. This note is a message which describes implemented changes.

$ git commit -m “<commit-message>”

Git push

Push command exports local commits from a precise branch to remote repository.

$ git push or $ git push <remote> <branch-name>

Conclusion

Every developer should know fundamentals of git version control system, it will increase skills of creating clean and complex apps.

Do not hesitate and learn this basic commands which are perfect to start with. Create an online repository and track every change by using Git.