Language: EN

instalar-git-en-raspberry-pi

How to Install and Use Git on Raspberry Pi

In this entry, we will explore how to install and configure Git on a Raspberry Pi. Git is a distributed version control system widely used in software development to manage source code, track changes, and collaborate with other developers.

Setting up Git on your Raspberry Pi will allow you to integrate your device into a collaborative development workflow and maintain a more efficient control over your programming projects.

What is Git

Git is a distributed version control system created by Linus Torvalds in 2005. Git allows you to:

  • Track Changes: Keep a record of changes made to the source code over time.
  • Branches and Merges: Work on different development branches and merge them efficiently.
  • Collaboration: Facilitate collaboration among multiple developers on the same project.

Git is essential for managing large and small software projects, from personal projects to team collaborations.

Installing Git

First, we update the system before installing new packages. Open the terminal and run the following commands:

sudo apt update
sudo apt upgrade

Next, we install Git, which is available in the Debian and Raspberry Pi OS repositories, using this command:

sudo apt install git

To verify that Git has been installed correctly, check its version with:

git --version

You should see a message similar to git version 2.x.x, where 2.x.x is the installed version.

Initial Git Configuration

After installing Git, perform a basic configuration to personalize user information. This configuration is used in commits to identify who made the changes.

Set your name and email with the following commands. Replace "Your Name" and "your.email@example.com" with your information:

git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"

These settings are stored in the ~/.gitconfig file and apply to all Git repositories under your user.

To confirm that the configuration has been applied correctly, use the following command:

git config --list

You should see the user information you configured, along with other default settings.

Basic Git Usage

With Git installed and configured, you can start working with repositories. Below are some basic commands to familiarize yourself with the Git workflow.

Create a New Repository

To start a new repository in an existing directory, navigate to that directory and run:

git init

This creates a new subdirectory called .git, which contains all the version control information for the repository.

Clone a Repository

To clone an existing repository from a URL (for example, a repository on GitHub), use:

git clone https://github.com/user/repository.git

This downloads a complete copy of the repository and sets up the connection with the remote repository.

Make Changes and Commits

To add files to the staging area and commit the changes, use the following commands:

git add file.txt

To add all modified files, use:

git add .

Finally, we commit the changes with commit

git commit -m "Commit message"

Check the Repository Status

To see the current status of the repository and modified files, use:

git status

View the Commit History

To view the commit history, use:

git log

This shows a list of all commits made to the repository, along with author information and the commit message.