Most important commands of git

How to create or initialize a git repository?

  • git init

  • Note: git init converts the normal folder into the local repository. which becomes our workspace

There are mainly three phases created in your local system logically :

  1. workspace

  2. staging area

  3. local space

Now read very carefully:

  • using the "git add ." you will transfer your data to the staging area.

  • Note: .(DOT) stands for all files in the current directory or you can specify the file name also.

  • using the `git commit -m "message you want to send"` you transfer your data from the staging area to the local repo.

About commit :-

  • Store changes in your repository, you will get one commit-id

  • it's 40 alpha-numeric characters.

  • it used SHA-1 checksum concept.

  • Even if you change one dot in repo, the commit id will get changed.

  • it actually helps you to track the changes.

How to see history of your logs?

  • when you execute the command git commit -m "provided message" that command creates a log and is also known as history.

  • git log (For viewing the history)

How to create a branch in git?

  • git branch <branch name>

How to change branch?

  • git checkout <branch name>

How to list all the branches?

  • git branch

How to delete a branch?

  • git branch --delete <branch name>

How to add a remote repo in your local repo?

  • git remote add origin <URL of your remote repo>

  • Now you can push your commits to your remote repo just by following the below command.

  • git push origin <branch name to which you want to push>

  • example: git push origin master

How clone remote repo?

  • git clone <URL of your remote repo>

Did you find this article valuable?

Support Gaurav-Jethuri by becoming a sponsor. Any amount is appreciated!