Git is a Version Control System created by Linus Torvalds the founder of Linux. It is distributed in nature and fully open source. Due to its distributed nature, you can store copies of your git repositories on multiple platforms(if it is a personal project) or with every team member (for team projects). Examples of platforms that will help store your git repositories include GitHub, GitLab and Bitbucket. Each of these platforms will provide different operational benefits but at the core, they help store our git repositories. This way, if anything happens to one of the git repositories, then you can recover an exact copy from any of those remote sources.
Why Use Git
- Keeps a comprehensive record of all file changes: Git will stack all the committed changes of your files in one directory. This means anyone who has access to this git repository can see the full history of file changes in the repository. This is very important in maintaining code versions. Also with the help of well written commit messages, you can know what was changed at each point in the commit history.
- Branching and merging: When working on code individually or in a team, branching is very important. A developer can create a new branch when working on a new feature or issue. This ensures that only production-ready code is in the main or master branch. When the task in the branch is complete, they can be merged with the main or master branch as production ready code.
- Collaboration: Git is a very useful tool for collaboration when developing in using code. Every developer gets a copy of the git repository containing the full history of the project. Each member of the team can work on their own branch and implement features independently of the other members. Members of the team therefore know their task, and what other members are working on. Once they are done and the code is reviewed, it can then be merged to the main branch.
- Viewing the file history and Reverting errors: Git allows you to travel back in time (metaphorically) to when your code was working after a commit introduces bugs in your software. This allows you to review and know exactly when things went wrong. Viewing file history on personal projects can also help you as a developer to view your growth over the years and predict some aspects of your software career.
- Backup: Before clicking on this course, you might have seen this line 'Spilled coffee on your PC and now all your work is gone🙇!? Or did your cat walk on the keyboard and now you don't know what new lines were added?' This is a clear depiction of the backup merits that git commits can offer. Git can also help you restore an exact copy of your last pushed code if you are using remote repositories or code hosting platforms. All of this can be done with a single command.
Integrating git into your development process
Git is available to users of all the major operating systems. Most of the Linux distributions come with git preinstalled. To make sure that you have git on your system, open your favourite command line interface and type $git --version. You should see an output similar to this: git version 2.30.2.Your version maybe different from mine. If you don't have it installed, follow the guides to install in on your operating system here -> https://git-scm.com/book/en/v2/Getting-Started-Installing-Git .
Git functionality is available via a cli, GUI tools and extensions in modern IDEs and editors. Initialing a git repository is as simple as typing $git init. This will initialise a git repository in the directory where the command was run by creating a .git directory.
In the next chapter we will define terms that you are likely to encounter in this course and later when working with git on a scale.