Git basics

sumit Jeswanisumit Jeswani
2 min read

Most Used git commands

git init

git init

git init command id used to initialize the black repository. It creates a .git folder in the current working directory. This .git folder will be a hidden folder that contains a bunch of directories and configuration files. Whenever the git repository is created for the first time, it creates a branch called master.

git add

git add .

or

git add <file names or directory names>

The git add command adds all (or particular file) changes in the working directory to the staging area. The staging area contains the files which are going to be part of the next commit. We can check the files which are in the staging area using the command git status.

git status

git status

The git status command helps to check which files are untracked or are in the staging area.

git commit

git commit -m "message for commit"

git commit command is used to save the changes to the local repository. The command helps to keep a record of all changes you made. You can also put a message with each commit using the -m flag after the command and then your message between " ".

git remote add

git remote add origin https...Repository Link ..... .git

The git remote add . In the above code snippet origin is a variable where a remote repository link is stored.

git branch

git branch -M main

The command git branch creates a new branch with the provided branch name along with the command. To delete the branch you can use the -d flag (command git branch -d ).

git push

git push -u origin main

The command git push pushes the git directory to the Github. Here in the above code snippet origin is a variable where a remote repository link is stored.

These were some of the basic git commands that are mostly used. I hope you found this article informative. ๐Ÿ™‚

0
Subscribe to my newsletter

Read articles from sumit Jeswani directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

sumit Jeswani
sumit Jeswani