Step-by-Step Tutorial on Pushing Files to GitHub via Ubuntu Terminal
Introduction
If you're new to version control and want to collaborate on projects using GitHub, you've come to the right place. GitHub is a powerful platform that allows developers to share code, collaborate, and manage projects effectively. In this updated 2026 guide, we'll walk you through the steps of pushing a file to GitHub using the Ubuntu terminal — including the authentication method GitHub actually requires today, since plain password login no longer works for Git operations. Whether you're a beginner or looking to refresh your memory, we'll make the process easy and understandable.
Prerequisites
Before we dive into the process, make sure you have the following prerequisites in place:
- An active GitHub account
- Git installed on your Ubuntu machine
- A terminal emulator (like the default GNOME Terminal)
- A GitHub Personal Access Token (PAT) or an SSH key set up — required for authentication, covered in Step 6 below
Steps to Push a File to GitHub in Ubuntu Terminal
Create a new repository on your GitHub account
Step 1: Set Up Git Configuration
Before you start pushing files, it's crucial to set up your Git configuration. Open the terminal and enter the following commands:
git config --global user.name "Your GitHub Username"git config --global user.email "your.email@example.com"Replace "Your GitHub Username" and "your.email@example.com" with your actual GitHub username and email address.
Step 2: Navigate to Your Project Folder
Use the "cd" command to navigate to the directory containing your project. For instance, if your project is located in the "Documents" folder, you'd type:
cd ~/Documents/YourProjectFolderReplace "YourProjectFolder" with the actual name of your project folder.
Step 3: Initialize a Git Repository
If your project isn't already a Git repository, you need to initialize it:
git initSince Git 2.28, you can also set the default branch name at the same time, so your local repo starts on main instead of the older master default:
git init -b mainStep 4: Add Files to Staging
To start tracking your files, add them to the staging area using the following command:
git add filenameReplace "filename" with the actual name of the file you want to push. To stage every changed file in the folder at once, use git add . instead.
Step 5: Commit Changes
Commit the changes to the staged files with a meaningful message:
git commit -m "Your commit message here"Replace "Your commit message here" with a descriptive message that explains the changes you've made.
Step 6: Create a Remote Repository on GitHub
Go to your GitHub account and create a new repository. Follow the instructions on GitHub's website to set up the repository.
Step 7: Set Up Authentication (Required Before You Can Push)
GitHub no longer accepts your account password for Git operations over HTTPS — this was removed back in August 2021 and remains the case today. If you try to push with just a username and password, the push will fail with an authentication error. You have two options:
- Personal Access Token (PAT): Go to GitHub Settings > Developer settings > Personal access tokens, generate a new token with the appropriate repo scopes, and copy it immediately (it won't be shown again). When Git prompts for a password during push, paste the token instead.
- SSH key: Generate an SSH key pair on your machine and add the public key to your GitHub account under Settings > SSH and GPG keys. This lets you authenticate without entering a token every time, and is generally the more convenient option for repeated use on your own machine.
Whichever method you choose, set it up before attempting Step 9, or the push will simply fail with an authentication error.
Step 8: Add Remote Repository
In the terminal, link your local repository to the remote GitHub repository:
git remote add origin https://github.com/YourUsername/YourRepository.gitReplace "YourUsername" with your GitHub username and "YourRepository" with the repository's name. If you set up an SSH key in Step 7, you can use the SSH URL instead (git@github.com:YourUsername/YourRepository.git), which skips token prompts entirely on future pushes.
Step 9: Push to GitHub
Finally, push your changes to GitHub. Note that GitHub's default branch is now main, not the older master:
git push -u origin mainIf you're using a Personal Access Token, Git will prompt for your username and then a password — enter the token in place of the password. If you're using SSH, this step completes without a prompt once your key is set up correctly.
Conclusion
Congratulations! You've successfully pushed a file to GitHub using the Ubuntu terminal. This process is fundamental to collaborating with others and maintaining a well-organized version history of your projects. Remember that GitHub requires a Personal Access Token or SSH key for authentication rather than your account password, and that new repositories default to the main branch. Beyond that, practice makes perfect, so don't hesitate to experiment and explore more advanced Git features as you become more comfortable.


