- What is Git?
- GitLab
- How Git works and important terms
- Installing Git
- Main Git commands
- More information on Git
- Git Large File Storage (LFS)
- Sources
What is Git?
Git is a file version control system (VCS) which allows collaborative work. To put it another way, it is a system that allows you to store files, record and track changes, restore versions, create copies, compare files and merge code from different team members.
In conclusion, Git allows you to work with different co-workers or on different computers, at the same time, without the risk of overlapping changes or loss of versions.
GitLab
GitLab is a Git hosting tool, in other words, it is a web service for creating Git repositories (or projects). In addiction, it offers several extra features applied to Git and to manage a project.
In addition to file storage, with GitLab it is possible to:
- Create a project to start using GitLab and store files.
- Add members to a project, with different levels of access.
- Create a group to combine and manage projects together.
- Manage issues to collaborate on ideas, solve problems and monitor tasks.
- Create a merge request to request that changes made to a copy be merged with a project's main repository.
- Create milestones to organize problems and merge requests into groups.
- Follow your To-Do List with all user or group mentions, issues and merge requests you are assigned to.
More information and other features are presented in the GitLab documentation.
How Git works and important terms
In general, the workflow with Git follows these steps:
- Create a repository (project) with a Git online hosting tool (as GitHub, GitLab, Bitbucket ...)
- Clone (copy) this repository or a existing one to your local repository on your machine
- Make changes to the files in your working folder
- Add a file to staging area and commit (save) the changes on your local repository
- Push (send) your changes to your master branch (the main copy of the project) on server
- Pull (copy) the changes made by your team to your local machine from server
- Create a branch (your own version, a copy of the main project), make a change, commit the change
- Merge your branch to the master branch
To better comprehend this process it is important to understand some important terms and concepts for working with Git.
First, the difference between: working directory, staging area and repository.
In general, you edit your files in the working directory, then you add the files in the staging area, you save the changes in your local repository, and finally you save the changes in a Git online repository so that your co-workers can recover those files.
Work directory is where all the work is done: creating, deleting and editing your files on your computer.
Staging area or index is a temporary space where you determine which changes will be saved and where you list the changes you make to the working directory.
Local repository or HEAD is the place where the files from the Git repository are on your computer, that is, where the changes will be saved (but still on your machine).
Remote repository is where Git permanently stores these changes with the different versions of the project, in a way accessible to all project members.
The image below helps to explain the interaction between all these workspaces:
Source: Working with Git written by Chiamaka Ikeanyi
Second, what is a branch and its importance.
Branchs, in simple terms, are copies or versions of the project. The term Master Branch refers to the central copy, the main version of the project where all features are centralized. The creation of different branchs is interesting to develop features isolated from each other, so it is possible to create a copy of the project to test something separately. After the changes in a secondary branch are finished, it should be merged, that is, combined with the master branch. This process allows people to work separately on different parts of the project at the same time.
Installing Git
To install Git on Windows, click here and the download will start automatically. Just execute the file.
More information about Git installation and step-by-step installation on Linux and MacOS are found at https://git-scm.com/book/en/v2/Getting-Started-Installing-Git.
To check if Git was installed, run the following command in a terminal (Linux, macOS) or command prompt (Windows):
git --version
Main Git commands
Downloading, uploading documents and any other interaction between the user and the Git repository are performed using code commands executed via the command terminal of your operating system (You do not need to use the application installed on your computer). To start working with Git you can learn the main commands in this Common Git Commands Guide. If you need more examples you can access this page with Top 20 Git Commands With Examples. In addition, there are many other good tutorials on the internet.
In the Git Commands Wiki you will find a short summary of some of the most important commands.
More information on Git
The documentation is the most complete document on Git and its features. In reference you find all the commands involving git. For a complete manual you can access the book section.
Git Large File Storage (LFS)
Git was designed for storing small files and manage code versions. However, sometimes it can be interesting to add images, videos and tables, for example, to the git repository. These kinds of files are large and do not need to be versioned. Therefore, it is necessary to install the Git Large File Storage (LFS) tool.
To install the LFS extension, download this file and complete the installation by running the following code on your terminal:
git lfs install
In each Git repository where you want to use Git LFS, select the file extensions that you want to treat as large files with the following code. Then just run the git commands normally.
git lfs track "*.png"
It is not necessary to provide the exact name of the file, but only an extension of the file to which it is associated
git add .gitattributes
For more information you can access the GitLab LFS documentation.
Sources
https://livecodestream.dev/post/git-concepts-and-workflow-for-beginners/
https://medium.com/lean-in-women-in-tech-india/working-with-git-9dafa8f986b3
https://www.tutorialspoint.com/git/git_quick_guide.htm