TracksPractical Coding FoundationsVersion ControlUploading to GitHub(11 of 12)

Uploading to GitHub

So far, your Git commits exist only on your computer. That's fine for tracking changes locally, but what if your hard drive fails? What if you want to share your code with others or work from a different machine? This is where GitHub comes in.

GitHub is an online service that hosts Git repositories. Think of it as cloud storage specifically designed for code. When you upload your repository to GitHub, you get automatic backup, the ability to share your work, and tools for collaborating with others.

What Is a Remote?

In Git terminology, a remote is a connection to a repository stored somewhere else — usually on a service like GitHub. Your local repository can have multiple remotes, but most projects have one called origin that points to the main online copy.

Creating a GitHub Repository

First, create a repository on GitHub through their website. Sign in, click the "New repository" button, give it a name, and choose whether it should be public or private (private should work fine for now).

Don't initialize it with a README if you already have local commits — you want an empty repository to push to.

  • Note: you can use other Git hosting services such as GitLab, BitBucket, etc. GitHub is probably the most popular however.

After creating it, GitHub shows you the repository URL. It looks something like https://github.com/username/repo.git.

Connecting and Pushing

Back in your terminal, navigate to your local repository and add the remote:

The git remote add command creates a connection named origin pointing to your GitHub repository. The git push -u origin main command uploads your main branch to GitHub. The -u flag sets up tracking, so future pushes are simpler.

After that initial push, whenever you make new commits locally, you just run:

git push

Git remembers where to send your changes.

Why This Matters

Pushing to GitHub transforms your local project into something shareable and safe. Your code is backed up, you can access it from anywhere, and you're ready to collaborate with others. Most professional developers push their work to a remote repository daily — sometimes multiple times per day.

See More

Further Reading

You need to be signed in to leave a comment and join the discussion