Init and First Commit

In the following steps, we will learn the very basic commands to control a project folder with git. Then we will make changes to the project files and save the snapshots into the git repository.

Time for Action—Project initialization

  1. Create a folder for our project. Let’s name it “Sample Project”.
  2. Create some files inside the project folder. Optionally, put some dummy content in the files.
  3. Run the git init command.
    $ git init
    The git init initials the current folder as a git controlled repository.
  4. Run the git add . command to mark the files to be version controlled.
    $ git add .
    git add requires the input of files to be added. the . means adding all files in the current directory.
  5. Run the following git commit command to commit the marked files into the repository. This is the step that really save the changes as a snapshot.
    $ git commit -m "First commit."

NOTE: As a beginner, it’s easy to forget the commit message. git commit requires the message exists, but sometimes beginners try to avoid it by using -m "". This will lead to rejection from Git with message “Aborting commit due to empty commit message.

Further steps

We have learnt the add and commit command. By using these commands, now you can make changes on your files/source code. When you feel that needs a snapshot, you can git add the changed files and git commit them into the version-controlled repository.

NOTE: You can combine the add and commit into one command: git commit -am "<MESSAGE>". It adds all the changes into commit. Use it carefully.