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
You’ll get some thing like this :
Add Changes to the index (Stage) :
Now let’s create a new file file.txt and check the status:
$ git status
To add the file file.txt to the index we use:
$ git add file.txt
which give us:
Remove Changes (or file ) from index (Stage) :
To unstages files we can use :
$ git rm --cached file.txt
Which means that:
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 "
Which means that:
Perfect, but what if we modify the file.txt?
$ git status
Give us:
Then if we stage the file.txt (add it to the index):
$ git add file.txt
Modify the file.txt again to looks like this:
Which leaves us with:
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
git checkout - - file.txt
$ git reset -- file.txt
Copie file.txt from the stage to the working directory
Everything is clean again.
That’s it & see you soon!.