DEV Community

Sarah Bartley Dye
Sarah Bartley Dye

Posted on

Connecting Your Computer with GitHub-Part Four

There is one concept left to learn in the Connect Your Computer with GitHub lesson. Today’s post will focus on pushing repositories to GitHub. Skillcrush students learn why developers push repositories to GitHub and how to push a repository to GitHub.

What does it mean when developers push a repository to GitHub?

Pushing repositories to GitHub happens every time you use Git and GitHub. You will use the git push command regularly when working with a repository. When a developer pushes a repository, the changes they have made to the local repository are sent to GitHub.

Consistency is crucial in programming, especially when collaborating with other developers on GitHub. The git push command helps make this possible, so everyone is on the same page. This command moves all the commits developers made to a local repository on their computers and sends them to the remote repo on GitHub.

Skillcrush instructs students to consider any changes they have made to the repository on their computers, as these changes are saved locally. That means this version is different from the original project saved on GitHub. You will need to use the git push command to make sure both the local version and the GitHub version are current.

The git push command takes the commits you make from the local repository and move them to the remote repository on GitHub. To push code from the main branch of the local repo, type git push origin [branch name].

git push origin main
Enter fullscreen mode Exit fullscreen mode

The origin keyword means the repository the clone was copied from. Skillcrush says this is a forked repo on the GitHub account. The main keyword in this example refers to the branch you are adding your commits to.

You just need to check which branch you are sending your commits to. When I started learning how to code in 2015, GitHub used master instead of main, so some repositories could still use master instead of main. It never hurts to double-check everything when it comes to working with Git and GitHub.

Git Pull

After you type the git push command like the example, Git will take the main branch of your local repo on your computer and push any commits you’ve made to GitHub. GitHub will check the log of commits in the local repo with the commits on GitHub. If the commits aren’t on the local repo, Git will let you know by sending a message and telling you that you need to get these commits from GitHub.

A command that will help in these situations is the git pull command. The git pull command will pull commits from the GitHub repo for you. Type git pull followed by the remote repository name.

git pull example
Enter fullscreen mode Exit fullscreen mode

Once you get these commits, merge them into your local repo. After you do this, you can push anything to GitHub. Type the git push command just like the example near the top of this post.

When you press Enter, Git will send commits to the main branch of that remote repository that the “origin” is going to. Remember, the only changes that have been added to staging and are committed will be moved to GitHub when you use the git push command. Make sure to run the git status command to check that everything you want to send to GitHub is committed.

When your code hasn’t been saved, added, or committed yet, the computer might send a message to let you know that the repository is up to date. All that is left to do is push your code to GitHub.

How to Push Your First Repo to GitHub

Ready to push the repository you have been working on to GitHub. Here’s a step-by-step guide to move your commits to GitHub.

Step One: Start on the command line (Git Bash or Terminal, depending on what type of computer you are using). Go to the repository you want to push. If you don’t have a repository yet, please revisit the post Create the First Repo in this series.

Don’t forget to use the pwd command to make sure you are in the right directory. Look for the repository name listed at the end of the file path. It might look like this:

/Jane/Documents/my-first-repo
Enter fullscreen mode Exit fullscreen mode

The file path in this example is saying my-first-repo is going to be inside the Documents folder. The document folder is in Jane’s home folder. When you read a file path, start at the end and read to the left to find the right directory.

Step Two: Make sure you are also logged into GitHub and are on the GitHub dashboard. Look for a green button on the left sidebar next to the “Top Repositories”. Click this button.

When I create a new repository at the time this post is being published (2026), I am on the overview tab underneath my username. I switch to the repositories tab and click the “New” green button at the top of GitHub. It is next to the type, language, and sort dropdown menus.

Name your new repository. Skillcrush recommends using the same name as the repository you are trying to push. You can add a description if you like, but it isn’t required.

Keep the repository set to public and leave the default settings. Make sure the README checkbox is unchecked. Click the green “Create Repository” button when you are ready.

Step Three: GitHub will provide several different options for what you can do on this new page for creating repositories. Before exploring these options, ensure that you are using the SSH setup. Skillcrush has students push repositories from the command line so look at the headings for one that says “or to push an existing repository from the command line”.

When you find this heading, you can see all the commands you’ll use to push the code. You can type each of these lines in the command line, but GitHub provides an icon button that will copy everything for you so you can paste it in the command line.

These lines will do three things:

a.) Add the remote origin (GitHub) repository to your local repository.
b.) Change the brand name to main (if needed).
c.) Push the main branch to GitHub and set it as the default branch.

Step Four: Go back to the command line. Paste the lines you copied from step three and paste them in the command line. Press Enter when you are done. Let the command line process everything.

When it stops running, go back to GitHub and refresh your page. Your repository should appear now with all the files inside.

Are you not able to push to your GitHub repository?

You might get a message that says you don’t have permission to push any commits to GitHub. If you receive this message, you will need to run 'git remote -v'. When you use this command, it will display the remote origin repository associated with the directory.

When the computer displays this information, check the username. Is it set to yours or something different? If it is set to a different username, you will need to rename it. Use this example below to set the url.

git remote set-url origin the-url-you-just-copied
Enter fullscreen mode Exit fullscreen mode

Press Enter when you are ready, and the computer will replace the username with your username in the url. Type git remote -v again to double-check everything has been changed. Next, try pushing your commits to GitHub again.

Top comments (0)