Skip to main content

Command Palette

Search for a command to run...

Git for Beginners: Basics and Essential Commands

Published
3 min readView as Markdown

As we know for the developer we have to work with team and also along with them we have to track our code progress, So for the tracking purpose we use the Git as the code tracker in which we can track our every changes of the code. without using external database to store the log, we store the log in our working directory

The mainly use of the Git is to track the every changes done by the developer. It will help in the long term productivity, version control of the big projects and the bug finding in the code by some commands given by the git for the various controls like adding the changes, find out the difference between the previous and the current changes, get the log of all the changes etc.

working directory of git

In the above image you can see the working directory of the .git/ which contains all the files named as hooks, info, logs, objects, refs etc. you can see all the logs changes are been control by some files in the directory.

if we want to track our code by the git we use git init command in the terminal then hidden file name as “.git/ “ initialize in our directory which we should not change directly but by using some commands provided by the git for the various things like adding to staging to all the changes by git add “file name“ in the code then we save those changes by git commit -m “commit name“ it will create the new node of the changes with the hash value and our commit name we provide for more description and the latest added node will be the Head node. And there are lots of different commands of the git we use for the getting the status, difference between two nodes and also log of the all commits. It will help in finding the bugs and also resolve them separately without harming the rest of the code.

In the Git the common used commands are as follow:

  1. git init for initialization of the git

  2. git add “file name“ add to the staging

  3. git add . adding all the files to the staging

  4. git status giving the status of the node

  5. git log gives all the commits

  6. git diff “hash node1“ “hash node2“ gives the different of the two nodes provided

  7. git revert "node id" it will be give undo all the changes

  8. git reset --hard “node-id“ get to provided node-id without taking track (not recommended)

Above are some common git commands we are generally used for the code tracking

conclusion: Basically, git is the code tracker which is used to track the code by some commands provided by git and it will help in version control, easily revert changes and also for more productivity