The 6 basic commands to start a project with Git
NicolasBrondinBernard
Git is a super-powerful tool with hundreds of different commands, but here are a few basics!

Article published on 08/03/2021, last updated on 10/08/2026
Git is what's known as a decentralized version control system, which means that each contributor works on their own local version, and must regularly synchronize their changes with the remote repository or repositories.
Why have multiple remote repositories? Because generally a main remote repository is used for backup and collaboration (read and write), but others can also be used solely to deploy the code in a specific version.
Most cloud hosting providers work this way: you "push" a new version of the code to them, and they deploy the new version of the application.
Initializing the local repository
$ git init
It's thanks to this command that our simple project folder becomes a versionable folder, it will generate a hidden folder called .git which will contain all the metadata Git needs to manage code versions (configuration, history, etc...)
Linking a remote repository
$ git remote add [name of the origin] [url]
Being able to version your code locally is a very powerful feature for managing a project, but if you need to collaborate with other developers, or even ensure that your code is backed up in multiple places, you'll need to create a reference to a remote repository.
Thanks to this command, we're going to link our local repository to a remote copy, and take advantage of backup and project management features like those offered by platforms such as Github or Gitlab, for example.
In most cases, the name of the origin is simply "origin", but nothing stops you from changing it, or adding several origins with different names!
Displaying changes in the local repository
$ git status
Before saving our modifications, it can be useful to know exactly what changes have been made in our local version, which files have been created, modified or deleted so they can be added to the backup.
Adding one or more files to the next backup
$ git add [file or directory]
Git only saves changes to files that the user has explicitly requested to track. This command therefore tells Git that the file(s) in question should be added to the next backup if they have been modified!
Creating the local backup
$ git commit -m "[message]"
Allows you to save the modifications made to the files that were previously explicitly added, and to attach a message to them (important for knowing at a glance what was modified).
Retrieving any remote backups
$ git pull [name of the origin] [branch]
Before sending all your local backups to the remote copy, it's necessary to check that no other modifications have previously been saved remotely.
This check is generally only necessary if several people are collaborating on the same project.
Git gives you the ability to manage several versions of the same project and to easily switch from one version to another; to do this it uses identifiers called branches. The main version of a project is found on the "master" branch, sometimes also called "main".
If someone else has modified the same files as you on the same branch, the pull command may result in a conflict that you'll need to resolve locally before you can save the corrected version.
Sending all new local backups to the remote repository
$ git push [name of the origin] [branch]
Once your local version is clean, and you've saved all the changes made to your copy of the project with Git, the push command lets you send your local backups directly to the remote repository.
It's only once they're saved on the remote copy that your changes are secured and accessible to the other contributors of the project.
Complete courses, exercises and certificates to really learn programming!
4.8 average rating
No comments yet