DEV Community

Charles 🛰
Charles 🛰

Posted on

Basic git command you have to know.

I will talk about the basic commands about GIT you have to know.

First you need to have installed git.

For now on i will assume that you have installed git.

There are several ways to use git but i will show in the two more basic ways you would need to use it.

Maybe you saw a github repository that you want to saw at your code editor or you want to test it localy or for work or whatever reason you have.
You will need to run on the console the following command
git clone https://github.com/lautaroCharles/typeApp.git

You will have to replace the url with the url you want.

Once you run the command you will be able to cd inside the folder and be able to see the code or even run it.

Now let's talk about if you want to publish your code on github

First thing you will need is to be inside your project folder. Once you are there you will have to run the following command
git init
This command will initialize git.

After that you will need to run a command to add your code into the staging area
git add .
the command above will add your files into the stage area, but maybe you just want one file, for that you will have to run this
git add index.js
This way you just will add the changes you made inside index.js

Now that you have your code on staging area we can make a commit with a clear comment, in other blog i will explain how to make clear commits.

git commit -m 'first commit'

Now we just have two more steps
git remote add origin https://github.com/lautaroCharles/typeApp.git

On the url you will put your empty repository so after that we can push our code like this
git push -u origin main

Now we just have to go to our github repository and see our upload

I will leave some other useful commands
git status: See what is the status of your code, if you have something on staging or something that you can pass into staging.
git branch: See what branches do you have into your repository
git checkout main: (main is the branch name which can have another name) With this command you can change the branch that you currently are.

I will leave this link which a bunch of other git commands link

Top comments (0)