Git is a control version system used to mantain a history of changes as we continue developing the code of our application.
Instalation
Go to https://git-scm.com/downloads and download the instaler. Execute with all default values.
Configuration
In out machine we have to tell Git who we are (name and e-mail). That way we will sign all our commits. We launch Git Bash and introduce the next commands:
git config --global user.name "[name]" git config --global user.email "[email address]"
Creation of a local repository
There are two ways of creating a local repository: create it with init or with clone.
To create it, we use:
git init [project-name]
And to clone it:
git clone [url]
Committing changes
After changing our files (this includes to create, modify or delete files or folders) in our workspace, if we want to register those changes in out repository locally, we need to add them to the stage and, after, register them.
To add the changes to the repository:
git add [file]
To register the changes in the local repository:
git commit -m "[descriptive message]"
Upload changes
Once the changes are registered in our local repository, it is possible to upload them to a remote repository (like GitHub). This is done with the following command:
git push
In this point other user could syncronize and get our code.
Sycronize changes
Supposing there is any change in the remote server (like GitHub), we have to perform two steps to update:
First, it is needed to get the commit history of the branch in where we are. This is done with:
git fetch
Last, we have to download the changes what are inside those commits to the local repository.
git pull
Create branches
If we want to stop working in the master branch, we can create other branches (that will content the same code of the branch we are situated on). To do this, and being on the master branch, we launch the following command:
git branch [branch-name]
And after we situate on that branch with the command:
git checkout [branch-name]
Do merge between branches
It is possible that several teammates could be working simultaneously in different branches. At the moment of grouping every code in the same branch it will be necessary to perform a “merge between branches”. To do this, we situate on the branch we want to receive the code of the other branch, and launch the command:
git merge [branch]
Where “branch” is the other branch whose commits we want to get.
Compare changes before uploading code
If we are not sure about the changes between our workspace and our local repository, we can list those changes with the following command:
git status
Review the history of commits of a branch
After situating on the branch, to review the executed commits, we launch:
git log
So, what do you think ?