Malekbenz

Hi, I'm MalekBenz. I author this blog, I'm FullStack Developer, create courses & love learning, writing, teaching technology. ( Javascript, C#, ASP.NET , NodeJS, SQL Server )

Git Basics

In this toturial we are going to understand some basic Git commands by practice. if you don’t know Git (Git is distrubuted version control system)..

I assume that you have already have Git installed.

Create new git repository

Let’s create a new directory and name it learngit:

 $ mkdir learngit
 $ cd learngit

Then to create a Git repo you type :

 $ git init 

CMD

You’ll get some thing like this :

CMD

Add Changes to the index (Stage) :

Now let’s create a new file file.txt and check the status:

 $ git status 

CMD

CMD

To add the file file.txt to the index we use:

 $ git add file.txt 

CMD

which give us:

CMD

Remove Changes (or file ) from index (Stage) :

To unstages files we can use :

 $ git rm --cached file.txt 

CMD

Which means that:

CMD

Commit changes:

Now to commit our changes let’s first stage our file file.txt again :

 $ git add file.txt 

We commit by typing :

 $ git commit -m "My First commit "

CMD

Which means that:

CMD

Perfect, but what if we modify the file.txt?

CMD

  $ git status

Give us:

CMD

Then if we stage the file.txt (add it to the index):

  $ git add file.txt

CMD

Modify the file.txt again to looks like this:

CMD

Which leaves us with:

CMD

Now let’s have some fun with Git :

git reset - - file.txt

Copie file.txt from the latest commit to the stage:

  $ git reset -- file.txt

CMD

git checkout - - file.txt

  $ git reset -- file.txt

Copie file.txt from the stage to the working directory

CMD

Everything is clean again.

That’s it & see you soon!.

Comments