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
- Create a folder for our project. Let’s name it “Sample Project”.
- Create some files inside the project folder. Optionally, put some dummy content in the files.
- Run the
$ git init
git initinitials the current folder as a git controlled repository.
- Run the
git add .command to mark the files to be version controlled.
$ git add .
git addrequires the input of files to be added. the
.means adding all files in the current directory.
- Run the following
git commitcommand 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.”
We have learnt the
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
commit into one command:
git commit -am "<MESSAGE>". It adds all the changes into commit. Use it carefully.