Categories: Quick Tips

Upload Files to GitHub from the Command Line

GitHub is an online version control system that allows individuals or teams to manage revisions to a codebase over time.

This allows developers to have multiple versions of the same codebase and gives room for developers to build out new features without breaking changes to the working version.

Atlassian has a good resource on version control and it’s benefits.

Uploading The Files to GitHub via Terminal

To start using GitHub, you need to create an account on github.com. From your dashboard, create a new repository.

On the next screen, enter a name for the new repository, select your preferences and click “Create repository.”

Once the repository has been successfully created, you would see a screen similar to this:

GitHub gives instructions on how to upload files from the command line so we’ll use the instructions.

Switch to your local terminal/command line. If you don’t have Git installed, you would need to download and install it.

Run the following commands:

mkdir github-upload
cd github-upload

mkdir creates a new directory. cd switches to the new directory.

touch README.md

This creates a new file in the current directory named README.md. Open up the file in any text editor (VS Code, notepad++) and add the following:

# Hello World

Save it and switch back to your terminal.

git init

This command creates a local Git repository on your system. Basically initializes everything Git needs to track and manage the files in the repository.

git add README.md
git commit -m “Initial commit”

git add adds the file README.md to the current “working tree.” The working tree contains files that Git is tracking. git commit captures the files that are currently being tracked and saves them in their current state. This can be thought of as a “safe” version.

git remote add origin https://github.com/USERNAME/REPOSITORY-NAME.git

This command tells Git to connect your local repository to the remote one at https://github.com/USERNAME/REPOSITORY-NAME.git, which is hosted on GitHub. Use the link provided in the previous step after creating the repository. origin will serve as an alias to the remote repository.

git push -u origin master

Uploads the local repository to the remote one on GitHub. It would ask for your GitHub credentials if you’ve not entered it before. Once it has been uploaded, refresh the page on GitHub. It should look like this:

That’s it. You have successfully uploaded a file to GitHub from the Command-Line.

Deven Rathore

Deven is an Entrepreneur, and Full-stack developer, Constantly learning and experiencing new things. He currently runs CodeSource.io and Dunebook.com.

Published by
Deven Rathore

Recent Posts

Free Applications and Websites to Enhance Coding Skills

Obtaining any skill means that one will continuously upgrade it to become professional. It’s impossible…

3 weeks ago

How to Use Disk Drill Partition Recovery Software for Mac

With the keyboard shortcut "Command(⌘) + Option(⌥) + Delete(⌫)" you can completely remove a file…

3 weeks ago

21 React Project Ideas for Beginners

For some weeks now, you have been putting in a lot of effort in understanding…

1 month ago

Reasons for Creating a Custom Transportation Management Software

Transportation management software is used by organizations to administer, control, and manage the transportation aspect…

1 month ago

21 Angular project ideas for beginners

Angular project ideas have become so handy in bringing evolution and slight changes to many…

2 months ago

Tips for Optimal SaaS Platform Development

According to BetterCloud, approximately 80 percent of mobile applications will be running on mobile software…

2 months ago