Create a git project ( git init )

Create a project folder e.g. my_project

$ mkdir my_project

Then, change directory to your project folder.

$ cd my_project

Make sure you have git install on your computer. To check this, simply type git or git --version

$ git --version
git version 2.3.2

To initialize a new git repository, simply type git init. This command initializes a directory and converts it to a Git repository. When the repository is initialized, Git creates a hidden directory called “.git” inside the top level of the repository. Git will store a bunch of information about the repository in there.

$ git init
Initialized empty Git repository in /Users/robin/Dropbox/GitProject/my_project/.git/

To see the hidden ".git" folder, you need to type ls -a

$ ls -a
. ..  .git

So here you see git has folders and files, basically this is how git track all movements and differences.

$ ls .git
HEAD        config        hooks     objects
branches    description   info      refs

Tell git who we are

Before adding any file and doing any commit, we need to tell git who we are:

$ git config "Robin"
$ git config ""

From this point of time, if we add any file or do commit, git is going to know who did those changes.

In addition, instead of doing this every time for a new project, we can pass a flag called global to setup the user in your home folder level.

$ git config --global "Robin"

Check project status ( git status )

To check the current git status

$ git status
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)

It tells us:

  • Currently on master branch. (Master branch is the default branch.)
  • Currently on an initial commit.
  • There is nothing to commit at this time.

Suppose you have created a new file called test_1.txt.

$ git status
On branch master
Initial commit
Untracked files:
  (use "git add <file>..." to include in what will be committed)
nothing added to commit but untracked files present (use "git add" to track)

To start tracking the 'test_1.txt' file, you need to use git add <file>

$ git add test_1.txt

Then, by typing git status again, you will see:

$ git status
On branch master
Initial commit
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
   new file:   test_1.txt
Now, the 'test_1.txt' is in stage.

The file is in the stage and if you are ready to save this work, simply type git commit to take a snapshot. (Note: git commit take all the files in the stage format and package them as an one snapshot. )

$ git commit -m "first commit"
[master (root-commit) 760f2bb] first commit
  1 file changed, 1 insertion(+)
  create mode 100644 test_1.txt