At Starting with Git on Linux (Part 2), we talked about configuring our Git account, setting up the username and email address. Also, we learned how to clone a GitHub repository in our Linux machine.
In this part, we will talk about initializing a repository, starting version controlling and proposing changes.
If you need to start tracking an existing project in Git, you need to go to the directory where the project is. After that you should type:
$ git init
This command creates a subdirectory named .git . This subdirectory contains all the necessary information about your repository files. But, in order to start controlling existing files, you should begin tracking the files and do the initial commit.
See the commands below and their explanation to see how they work.
$ git add *.c
$ git add LICENSE
$ git commit -m "Initial project version"
git add helps for tracking files and proposing changes.
Usually you will use:
$ git add where
If you want to add multiple files you can run this command:
$ git add file1 file2 file3
The following code serves to commit the changes:
git commit -m "Commit message"
You must imagine a commit as a snapshot in time where you can return back in anytime to access your repository at that stage. You can associate a commit message with every commit, which you can provide with the -m prefix.
It is recommended to provide a useful commit message because it helps you in identifying what you changed in that commit. Don’t use just “Fixed” in your message. You should add what’s the problem that you fixed in that commit.
In this part we explained initializing a repository, starting version controlling and proposing changes. In the following days, I will continue this tutorial. If you have any questions write me in the comment section.
This article is part of the series Starting with Git on Linux.