A guide to setting up Git and GitHub on Ubuntu Linux

|

|

This guide covers installing Git on Ubuntu and setting up a GitHub account for version control of your code projects. It includes steps like updating Ubuntu, installing Git, and adding SSH keys to GitHub. After setup, it explains how to create, clone, and manage code repositories locally and on GitHub, ensuring efficient coding collaboration and…

This article explains how to install and use Git and GitHub on Ubuntu Linux.

Git is a powerful distributed version control system that allows you to track changes in source code during software development. GitHub is a web-based hosting service for version control using Git.

By installing Git on Ubuntu and setting up a GitHub account, you can use these tools to manage your code with version control. This allows you to keep track of changes to your code over time, collaborate with others on code development, and revert to previous versions of your code if necessary.

Additionally, using Git and GitHub can help streamline your workflow and make your code development process more efficient.

Setting up a GitHub Account

If you don’t already have a GitHub account, follow these steps:

  1. Go to GitHub’s website and click on the Sign up button.
  2. Fill in the required details and create your account. Make sure to verify your email address.
  3. Once your account is ready, you can sign in to GitHub.

Installing Git on Ubuntu

Before you start, ensure you have a terminal window open (you can open one using. Ctrl + Alt + T).

Update package lists:

sudo apt update  

Install Git:

sudo apt install git  

Verify the installation:

git --version  

This should output the installed version of Git.

Configure Git (optional):

Run the two commands by replacing “user_name” with your GitHub username and “youremail@example.com” with the email you used to create your GitHub account.

git config --global user.name "user_name"
git config --global user.email "youremail@example.com"

Generating SSH Keys

To securely communicate with GitHub from your computer, it’s best to generate SSH keys.

In your terminal, generate a new SSH key (replacing the email with the one you used for GitHub):

ssh-keygen -t ed25519 -C "youremail@example.com"  

Press Enter to accept the default file location.

Set a secure passphrase when prompted.

Start the ssh-agent in the background and add your SSH private key:

eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_ed25519  

Now, add the SSH key to your GitHub account:

Copy the SSH public key to your clipboard:

cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard  

(If xclip isn’t installed, you can install it using sudo apt install xclip)

Go to GitHub, click on your profile picture in the top-right corner, and go to Settings.

Go to SSH and GPG keys in the side menu and click New SSH key.

Paste your SSH key into the field and save.

Creating a Repository on GitHub

  1. Log into your GitHub account.
  2. Click the plus sign (+) in the top right corner and select New repository.
  3. Give your repository a name, choose whether it should be public or private, and click Create repository.

Creating a local repository

Create a folder on your system. This will serve as a local repository and later be pushed onto the GitHub website.

Use the following command:

git init Myrepo

If the repository is created successfully, then you will get the following line:

“Initialized empty Git repository in /home/ricahrd/Myrepo/.git/”

Add Files to the Repository

After cloning a repository or if you have an existing directory that you want to track with git:

cd Myrepo
touch README.md
git add README.md

Commit Changes

To save your changes locally:

git commit -m "Add README"

Use a meaningful message that describes the changes you’ve made.

Push Changes

To send your committed changes to GitHub:

git push origin main

Make sure to replace main it with the branch name you wish to push to if it’s different.

Pull Changes

To update your local repository with the latest changes from GitHub:

git pull origin main

Again, replace main with the appropriate branch name if necessary.

Clone a Repository

To create a copy of a repository on your local machine:

git clone <repository URL>

Replace <repository URL> with the URL of the repository you want to clone (which you can find on the repository’s GitHub page).

And that’s it!

Conclusion:

This post showed you how to install and use GitHub on Ubuntu Linux. Please use the comments form below if you find errors or have something to add.


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading