Chuck's Academy

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:

  1. Go to the official Git website at https://git-scm.com and download the installer for Windows.
  2. 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
"The 'brew install git' command will install Git using Homebrew, a package manager for macOS. If you don't have Homebrew installed, you can find instructions at brew.sh."

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
"The 'sudo apt-get install git' command downloads and installs Git using the package manager of the Debian-based Linux distribution. Using 'sudo' grants superuser permissions to perform the installation."

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
"With the 'git config --global user.name' command, you define your name, while 'git config --global user.email' sets your email. This information is associated with each commit you make, allowing other developers to know who made the change."

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
"With the 'git config --global core.editor nano' command, you set the nano editor as the default editor for writing commit messages. You can replace 'nano' with your preferred editor."

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:

  1. Open your terminal and run the following command:
bash
"The 'ssh-keygen -t ed25519 -C your_email@example.com' command generates a new SSH key using the ed25519 algorithm. Replace 'your_email@example.com' with your email address associated with your GitHub account or another repository platform."
  1. You will then be prompted to choose a location to save the key. Press Enter to accept the default location.
  2. 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:

  1. Copy the content of your public SSH key with the following command:
bash
"The 'cat ~/.ssh/id_ed25519.pub' command shows the content of your public key. Copy this content to add it to your GitHub account."
  1. Log in to your GitHub account and go to Settings -> SSH and GPG keys -> New SSH key.
  2. 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.

  1. Download and install SourceTree from https://www.sourcetreeapp.com.
  2. Open SourceTree and set up your GitHub account in Tools -> Options -> Authentication.
  3. 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.


Ask me anything