Git Basics

Git Basics

Git is an version controller tool developed by legend Linus Torvalds, which helps Developer tracking changes in any set of files, sometimes its a life saver, believe me

Learn Git fundamentals in this short blog OR use it as a cheatsheet for future references.

First initialize the present local directory

git init

Write some code

Stage the code to commit

  • Stage all files
git add .
  • Stage a specfic file
    git add file.html
    
  • Unstage a file
$ git restore — staged name.txt

Now commit the staged code

with a commit message for future references

git commit -m "First Git commit"

We can check commited code status by

git status

Check history of your commits

git log

Upload files to your Github Account

Now connect your Github Account and upload your files.

  • First, we need to create a Github repository

01.png

  • Copy the HTTPS link of your repository

02.png

  • Now add remote access to your GitHub repository

    git remote add origin https://github.com/sheoranharis/sheoranharis.git
    

    origin is name of the link to your repo

  • Create a branch by which you will push your code to the repo

    git checkout -b mybranch
    
  • We need remote access to our Github Account

    First, generate a SSH Key - Github Docs

    then add this SSH key to your Github account - Github Docs

OR

If you are using VS code, just login into VScode by your Github account and you are good to go.

Push your code to Github using Git

git push origin mybranch

We are pushing our code by mybranch to origin

Check your Github account to see changes

See you in next blog.....

Did you find this article valuable?

Support Harish Sheoran by becoming a sponsor. Any amount is appreciated!