How to Install Git and GitHub on Ubuntu: A Step-by-Step Guide
Install Git by opening a terminal and running “sudo apt update” then “sudo apt install git”. Configure Git with your username and email using “git config –global”. Create a GitHub account on their website and generate SSH keys to securely connect your local machine.
Pull Changes
Installing Git and GitHub on Ubuntu helps manage code and collaborate on projects effectively.
Git serves as a free, open-source version control system (a tool that tracks changes to files over time) to monitor every modification in your codebase. It records a complete history of development work.
GitHub operates as a web-based platform that uses Git to host code repositories. Sharing, collaborating on, and managing software projects with teammates becomes much simpler through this service.
This guide covers installing and configuring Git, typically version 2.34 or newer on recent Ubuntu releases, along with setting up a GitHub account.
Setting up a GitHub Account
Beginning online project management requires creating a GitHub account first. Visit the GitHub website and select the ‘Sign up’ button. Providing basic details and confirming the email address completes account setup.
- Go to GitHub’s website and click on the Sign up button.
- Fill in the required details and create your account. Make sure to verify your email address.
- Once your account is ready, you can sign in to GitHub.
Installing Git on Ubuntu
Open the terminal to install Git directly on Ubuntu.
Update system package lists by running 'sudo apt update', then install the software package using 'sudo apt install git'. Type 'git --version' to confirm the installation. This command will show you the installed version of Git.
Configure Git (optional):
Configure Git with your username and email. Run these two commands, replacing "user_name" with your GitHub username and "youremail@example.com" with the email you used for your account: git config --global user.name "user_name" and git config --global user.email "youremail@example.com".
sudo apt update
Install Git:
sudo apt install git
Verify the installation:
git --version
This command will show you 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
Generate SSH keys (cryptographic access credentials) to connect with GitHub securely without typing account passwords for every push or pull. Open the terminal and type 'ssh-keygen -t ed25519 -C "youremail@example.com"', making sure to replace the example email with your actual GitHub email address. The terminal will then guide you through creating your keys.
Generate a new SSH key in your terminal by running 'ssh-keygen -t ed25519 -C "youremail@example.com"' (remember to replace the example email with your actual GitHub email). Press Enter to accept the default file location, then set a secure passphrase when prompted. Start the ssh-agent in the background and add your SSH private key:
ssh-keygen -t ed25519 -C "youremail@example.com" 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
- Log into your GitHub account.
- Click the plus sign (+) in the top right corner and select New repository.
- Give your repository a name, choose whether it should be public or private, and click Create repository.
Creating a local repository
Create a local Git repository by making a new folder and instructing Git to track it. Navigate to the target project directory inside the terminal. Run the command 'git init Myrepo' to spin up a new repository called 'Myrepo' in that exact spot.
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
Push Changes
Send local commits to a remote server using a push operation. Run `git push origin
git push origin main
If you're pushing to a different branch, be sure to replace main with that branch name.
Pull Changes
Pull Changes
This command updates 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
Cloning a repository means making a copy of an existing project from GitHub and putting it on your computer. To do this, use the command 'git clone' followed by the project's web address, which you can find on GitHub.
git clone <repository URL>
Replace <repository URL> with the URL of the repository you want to clone (which can be found on the repository's GitHub page).
And that's it!
Conclusion:
- The guide provides a comprehensive overview of installing Git and setting up a GitHub account on Ubuntu, allowing for efficient code management and collaboration.
- Following this article's steps, users can create a local repository, add files, commit changes, and push them to GitHub, streamlining their development process.
- Additionally, the guide covers essential commands such as generating SSH keys, creating a repository on GitHub, pulling changes, and cloning a repository, ensuring a well-rounded understanding of using Git and GitHub.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!