DEV Community

Cover image for Git Basics
Harish
Harish

Posted on

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
Enter fullscreen mode Exit fullscreen mode

Write some code

Stage the code to commit

  • Stage all files
git add .
Enter fullscreen mode Exit fullscreen mode
  • Stage a specfic file
git add file.html
Enter fullscreen mode Exit fullscreen mode
  • Unstage a file
$ git restore β€” staged name.txt
Enter fullscreen mode Exit fullscreen mode

Now commit the staged code

with a commit message for future references

git commit -m "First Git commit"
Enter fullscreen mode Exit fullscreen mode

We can check commited code status by

```
git status
```
Enter fullscreen mode Exit fullscreen mode

Check history of your commits

```
git log
```
Enter fullscreen mode Exit fullscreen mode

Upload files to your Github Account

Now connect your Github Account and upload your files.

  • First, we need to create a Github repository

Image description

  • Copy the HTTPS link of your repository

Image description

  • Now add remote access to your GitHub repository
git remote add origin https://github.com/sheoranharis/sheoranharis.git
Enter fullscreen mode Exit fullscreen mode
**origin** is name of the link to your repo
Enter fullscreen mode Exit fullscreen mode
  • Create a branch by which you will push your code to the repo
git checkout -b mybranch
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode

We are pushing our code by mybranch to origin

Check your Github account to see changes

See you in next blog.....Lets Connect

Top comments (0)