What is Git?
Git is a distributed version control system designed to track changes made to files in a project. It was created by Linus Torvalds in 2005 to manage the development of the Linux kernel.
With Git, developers can:
- Collaborate in teams without overwriting others' work.
- Maintain a complete history of changes in the project.
- Restore previous versions in case of errors.
Why use Git?
Git has become the de facto standard in software development for the following reasons:
- Efficient collaboration: Allows multiple developers to work simultaneously on different parts of a project.
- Complete history: Keeps all changes made, along with who made them and why.
- Security: Git data is hard to corrupt due to its design.
- Distribution: Each copy of the repository contains the full project history, so it doesn't rely on a central server.
- Flexibility: Works for projects of any size and complexity.
Installing Git
To start using Git, you first need to install it on your computer. Let's see how to do it depending on your operating system.
-
Windows
- Download the installer from https://git-scm.com.
- Run the downloaded file and follow the instructions in the setup wizard.
- During installation, you'll be prompted to choose settings like the default editor. You can keep the recommended options.
-
MacOS
- If you have Homebrew installed, you can install Git with:
brew install git - You can also download it directly from https://git-scm.com.
-
Linux
Use your distribution's package manager to install Git. Some examples:
- Ubuntu/Debian:
sudo apt-get install git - CentOS/Fedora:
sudo yum install git
To verify that Git is installed correctly, run:
git --version
Initial Git Setup
Once installed, it's important to perform an initial setup to personalize Git according to your identity and preferences.
-
Set up username and email
These values will be used to identify you in the commits you make.
-
Set your name:
git config --global user.name "YourName" -
Set your email:
git config --global user.email "YourEmail@example.com" -
To verify your configuration, use:
git config --global --list
-
-
Set up default editor
Git uses a text editor for tasks such as writing long commit messages. By default, it uses
vim, but you can change it to any editor you prefer. For example:- To set Visual Studio Code as the default editor:
git config --global core.editor "code --wait" - To set Nano as the default editor:
git config --global core.editor "nano"