Git is without a doubt the most useful tool for any developer of any kind. Whether you are working alone or with a team git is indispensable.
With this tool, everyone can work on the same project simultaneously, without being in the same place (which is quite normal these days), and allows you to keep track of your work. You have to respect some rules that we will see now.
Remember this mantra: “PULL-COMMIT-PUSH” you will understand later.
Let’s start in order, first, you need to install Git on your computer.
Instead, if you are a macOS user I suggest you install Homebrew from your terminal with the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
As soon as it is finished, just run this command in your terminal:
$ brew install git
Git is now installed on your computer and ready to be used.
GitHub, Bitbucket and GitLab
To use git you need one of these three. No matter which one you use, they all have the same goal, to give you space where you can keep your projects accessible at all times.
I chose to use GitHub, first of all, you have to register an account.
after you have completed your registration and responded to the verification email. You need to create your first repository.
This is a process to which you must pay close attention.
The fields to be filled out are the name of the project, a brief description of the project, the public or private visibility of the project.
Public: anyone can see your repository
Private: only you and people authorized by you can see and access it
Finally, we have “.gitignore. It’s a file that you can insert already when creating the repository, it allows git to exclude some folders and files according to your needs.
In my case, I have included one suitable for Unity, but you can choose according to your needs.
Now git is installed and you’ve created your first repository. Now it’s time to link your remote repository to your project folder on your computer. É piú semplice di quello che credi, non farti spaventare dal terminale.
I’ll leave you with some of the main commands you’ll need to use and a few tips to get you started.
wherever you want, just right-click and you can open the git terminal immediately.
If you do it inside a folder, it will open directly on the path of the folder you are working in. If instead, you want to move between directories the commands that you will use more are: ls and cd
ls short for list allows you to see the contents of the directory
cd short for change directory allows you to move between directories.
Open Git Bash directly in the folder you want to work in, and enter this command
now you’ve initialized your folder as a git repository, and with the next command, you can connect it.
git remote add origin https://github.com/your-name/your-project.git
you can find the address to insert on the page of your project on GitHub
do you still remember the mantra?
This operation allows you to catch up with the online project and with your colleagues, it is very important that it is done first. Skipping this step is the main cause of the conflicts that can be generated.
git pull origin master
A commit is the insertion of your change into the project. To do this we need to create the commit, as the first thing we need to see the modifications made with the command:
then you have to add the files or folders you want to include in the modification. You can insert one folder or file at a time or all at once with the following commands:
git add <folder/file>
git add .
this should be the result, in green the files that have been added and in red those that still need to be added
The last command you have to give is the one that will create the commit with its message ready to be sent.
git commit -m "your first commit"
always write the message is important for you and your colleagues, always try to be clear and concise.
we’re at the end. With this last line, you send your changes to the remote repository.
git push origin master
Congratulations you have completed your first commit.
Remember when you are working not to wait a whole day to send your changes but to break them down into small parts so that it is easy to move in the project.
It’s really over.
PULL - COMMIT - PUSH