GIT
Installation of Git and Initial Setup
Before starting to work with Git, we need to install it on our system and perform some basic configurations. In this chapter, we will explain how to install Git on different platforms and how to configure it properly to start working on your projects. Additionally, we will learn how to generate SSH keys to interact securely with platforms like GitHub.
Installing Git
Git is available for various platforms, including Windows, macOS, and Linux. Below, we will see how to install Git on each of them.
Installation on Windows
To install Git on Windows, follow these steps:
- Go to the official Git website at https://git-scm.com and download the installer for Windows.
- Run the installer and follow the instructions. During the installation, Git will ask you about various configurations, such as the default editor and the use of Git Bash. We recommend accepting the default settings.
Installation on macOS
To install Git on macOS, you can use the package management system Homebrew. If you already have Homebrew installed, simply run the following command in the terminal:
bash
Alternatively, you can download the installer from the official Git website.
Installation on Linux
On most Linux distributions, Git is available through the default package manager. For example, on Debian-based distributions like Ubuntu, you can install Git with the following command:
bash
For other distributions, such as Fedora or Arch Linux, the commands may vary slightly, but you can generally use your system's package manager to install Git.
Initial Git Configuration
Once you have installed Git, it is important to configure it before starting to work with it. The most important initial configurations are setting your name and email, which will be associated with each commit you make.
bash
You can also configure the text editor that Git will use by default to write commit messages. For example, to use nano as the editor, you can run the following command:
bash
Generating SSH Keys
To interact with platforms like GitHub securely, it is advisable to use SSH keys. This allows you to authenticate on these platforms without having to enter your username and password every time you perform an action.
Creating an SSH Key
Follow these steps to generate a new SSH key:
- Open your terminal and run the following command:
bash
- You will then be prompted to choose a location to save the key. Press Enter to accept the default location.
- Next, you will be asked to enter a password. This password is optional, but it is recommended to set one for added security.
Adding the SSH Key to GitHub
Once you have generated the SSH key, you need to add it to your GitHub account. Follow these steps:
- Copy the content of your public SSH key with the following command:
bash
- Log in to your GitHub account and go to Settings -> SSH and GPG keys -> New SSH key.
- Paste the content of the public key into the corresponding field and assign a descriptive name to the key.
Once you have added the key, you will be able to authenticate on GitHub using your SSH key without needing to enter your password.
SourceTree Configuration
If you prefer to use a graphical interface to interact with Git, SourceTree is a popular option. Below, we show you how to configure SourceTree to work with Git and GitHub.
- Download and install SourceTree from https://www.sourcetreeapp.com.
- Open SourceTree and set up your GitHub account in Tools -> Options -> Authentication.
- Generate a personal access token on GitHub if necessary and add it to SourceTree.
SourceTree will allow you to manage repositories and perform common Git actions, such as commits, merges, and push, without the need to write commands in the terminal.
Conclusion
In this chapter, we have covered the installation of Git on different operating systems, as well as the initial configurations necessary to start working with Git efficiently. We have also seen how to generate and add SSH keys to interact securely with cloud repository platforms like GitHub. In the next chapter, we will learn how to create and manage local and remote repositories, enabling us to start versioning our code.
- Introduction to Git and Version Control
- Installation of Git and Initial Setup
- Understanding Repositories
- Basic Workflow in Git
- Working with Branches in Git
- Collaborating with Other Developers
- Undoing Changes in Git
- Working with Tags in Git
- Rebase and Squash in Git
- Stashing and Cleaning in Git
- Advanced Git Commands
- Hooks and Automation in Git
- GitHub and Repository Management
- Best Practices in Git
- Conclusion and Final Tips