The best way to install and configure Git on Linux or macos

mr zlaam (admin)

Published: September 30th, 2024

The best way to install and configure Git on Linux or macos

Image by : Unsplash

Overview

Git is a widely-used, open-source distributed version control system, designed for managing projects of all sizes. It was originally developed by Linus Torvalds in 2005. Git keeps a history of code changes and allows for parallel code contributions. It's popular for its ability to handle both small and large projects with speed and efficiency. It's used by a significant number of software development job openings in the UK.

Installation

step-1

Mac OS

using brew

brew install git

Ubuntu/Debian/Linux-Mint

sudo apt-get  install git

Red Hat/CentOS/Fedora

sudo yum install git 
        # or
  sudo dnf install git

openSUSE

sudo zypper install git

Arch Linux

sudo pacman -S git

step-2

Check if git install properly by running the following command:

git --version

step-3

Now lets configure git properly so we can push and pull repos

1. Set the Gloabl user

You can run following commands to set the global user:

# Replace your actual email and username which you use on github
git config --global user.name "Your Name"
git config --global user.email "you@example.com"

2. Verify global configurations

Verify the global configurations by running the following command:

git config --global --list

3. Generate SSH keys

Generate the SSH-KEY by running the following command:

#  Replace with email you used earlier
ssh-keygen -t ed25519 -C "you@example.com"

4. Start the SSH agent in the background:

eval "$(ssh-agent -s)"

5.Add your SSH private key to the SSH agent:

ssh-add ~/.ssh/id_ed25519

6.Copy the SSH Key to Your Clipboard

After running the previous command you'll get SSH key display it using xclip

xclip -sel clip < ~/.ssh/id_ed25519.pub    # Make sure you have installed xclip

Alternatively, you can display the key and copy it manually:


cat ~/.ssh/id_ed25519.pub

Now you can see your ssh key on your screen copy it and add it on GITHUB SSH KEY

After adding SSH KEY now you can easily pull and push code files on github.

That's it for now, Let's Meet again