DEV Community

Cover image for Upload files to Github - a comprehensive guide
Aderibigbe Samuel
Aderibigbe Samuel

Posted on • Edited on

Upload files to Github - a comprehensive guide

You just finished a project on your local PC. You are looking for a place to keep it so that you can access it anywhere and anytime or you just started a new project and you will be developing over a long time with some of your friends but you need to make it accessible to them, Hold on this article is for you.

Over the years, GitHub has been the most popular internet hosting service for version control using Git. GitHub makes it easy for you to store your files, track changes made to your files and collaborate on software projects. Github also serves as a portfolio site where developers can showcase their work, ask others to review it and work on open-source projects. So I'm sure You would have known by now that using GitHub is a good idea for you.

In this article, I will be guiding you on how you can setup Git on your PC and start loading files to your GitHub account from your local computer.

Article Summary:

Create a Github account

Before you can start using Git and GitHub, the first thing is to download a GitHub account. Go to your browser and search GitHub or click this link github.com

Click on the signup button and follow the steps to finish setting up your account. Now that you have an account, You need to create a new repository. A Git repository helps to save and track all the changes made to your files.
To create a new repository, click on repositories and click on new. You can decide to make the repository private or public. Public, if you want others to have access to it and private, if you want to keep the files to yourself.

Image description

Extra tips: Choose a file name that gives an intuition about what your project is about e.g myPortfolioWebsite, LearningApp, Hotel_landing_page, etc also include a readme file where you write a good description of your project.

Download and Install Git

Before you can start using Git, you need it installed on your pc. There are different ways to get git installed on your pc but I will be explaining some of the easiest ways.

Window Users
Download the latest version of Git and choose either the 32-bit or 64-bit version depending on your PC (check your PC's information).

Image description
Install the downloaded file. Once installed, launch the Git bash and finish the setup.
You can read more on installing Git on windows here

Mac Users
For mac users, the easiest way is probably using a binary installer. Just go to https://git-scm.com/download/mac and choose the binary installer option, download the installer, and run it on your mac

Image description

Linux Users
Linux distribution comes with a package management tool that makes it simple to install git
From your shell, install Git using:

$ sudo apt install git-all 
Enter fullscreen mode Exit fullscreen mode

Verify the installation was successful by typing:

$ git --version 
Enter fullscreen mode Exit fullscreen mode

Configure Git

Now that you have successfully installed Git on your system, You need to do some setup to customize your experience using Git.
Git Email and username: replace 'savviesammie' with your GitHub username

$ git config --global user.name "savviesammie"
Enter fullscreen mode Exit fullscreen mode
$ git config --global user.email "savviesammie@gmail.com"
Enter fullscreen mode Exit fullscreen mode

Upload Files on GitHub

Remember the repository You created at the beginning of the tutorial? You will be cloning it on your pc and interacting with Git from your terminal. So go to your terminal and follow the tutorial.
cloning a repository means you are copying the repository from GitHub to your local computer.

Step 1: Clone the repository
Go to the repository you created on GitHub, click the green "code" button, and copy the link to your repository from the drop-down.

Image description

Step 2: Go to your terminal and type
git clone

$ git clone https://github.com/savvieSammie/password_manager.git
Enter fullscreen mode Exit fullscreen mode

Replace the "repository url" with the link you copied.
make sure you have a good internet connection on your pc as you will be downloading the directory.

Step 3: Put your files in the cloned repository:
Open the empty directory and add the files that you want to upload. Say for example, you have written some codes using a text editor and you have the file saved on your pc, transfer the file to the directory you cloned from GitHub and make sure to Confirm the list of files present

Step 4: Git add
Add the files to Git's staging area by typing

$ git add .
Enter fullscreen mode Exit fullscreen mode

Step 5: Commit the files to Git by using the git commit command

$ git commit -m "some message"
Enter fullscreen mode Exit fullscreen mode

replacing "some message" with a short description of the changes you made to the first. In your case, since it's the first time, you can just write "first commit"

Step 6: Set your remote repository
Earlier in step 1, you copied the url to your remote repository. You need it here to setup your remote repository, use the command
$ git remote add origin

for example:

 git remote add origin https://github.com/savvieSammie/password_manager.git
Enter fullscreen mode Exit fullscreen mode

Step 7: Git to push
push those files to your GitHub by using the command
$ git push

$ git push -u origin master
Enter fullscreen mode Exit fullscreen mode

The origin is your default remote repository name and the '-u' flag is upstream.
You will be prompted to fill in your GitHub username and password.

Now you can go to GitHub on your web browser, you will see the changes reflected.

Other Git Commands you need

git init - Initialize local a new repository
git status -shows what you have in your staging area
git add - adds files and folders to the staging area
git diff - compare and understand changes made to your files
git log - is used to view the log of the project's history.
git push - Takes a local repository and pushes to a remote repository (Github).
git show - to show the details of a specific commit
git pull - Pull latest changes from remote repository
*git clone *- Clone repo from GitHub

To view the official Git cheatsheet from Github, click Git cheat sheet

Conclusion

In this article, I have shown you how to create a GitHub account, setup Git on your PC and how to upload files from your local computer to GitHub. I also included some Git commands that you'll need.
By now, you should have Git running on your pc and also you have gained basic working knowledge of Git and Github.

Say hi to me on Twitter @Sammie_savvie

Top comments (0)