Skip to content

Latest commit

 

History

History
147 lines (93 loc) · 3.84 KB

File metadata and controls

147 lines (93 loc) · 3.84 KB
id push-changes-to-github
title Push Changes to GitHub
sidebar_label Push Changes to GitHub
sidebar_position 8
description Learn how to push your local commits to a remote repository on GitHub. Understand the difference between local and remote repositories and how to keep them in sync.
tags
github
git
push
commits
repository
beginners
version control
keywords
push changes
github push
git push origin main
remote repository
sync local and remote
beginners guide

Once you’ve made and committed changes to your local repository, the next step is to share those updates with your remote repository on GitHub. This process is known as pushing changes.

Pushing ensures your latest work is uploaded to GitHub so that you (and your team) can access it from anywhere.


What is "Push" in Git?

The push command in Git uploads your local commits to a remote repository. Think of it as “publishing” your changes to GitHub.

git push

When you run this command, Git sends your local branch’s commits to the corresponding branch in your remote repository (for example, main or master).

Step-by-Step: How to Push Changes to GitHub

1. Check your current branch

Before pushing, make sure you’re on the correct branch.

git branch

If you’re on a feature branch (e.g., feature/update-readme), Git will push that branch to the remote repository.

2. Link your local repository to a remote (if not already)

If your local repo isn’t connected to GitHub yet, add the remote URL:

git remote add origin https://github.com/<your-username>/<repository-name>.git

Then verify it:

git remote -v

You should see something like:

origin  https://github.com/ajay-dhangar/introduction-to-github.git (fetch)
origin  https://github.com/ajay-dhangar/introduction-to-github.git (push)

3. Push your changes

Now that your repository is ready, push your commits using:

git push origin main

or, if you’re working on a branch:

git push origin your-branch-name

Example:

git push origin feature/add-login-form

This command uploads all your local commits from the branch feature/add-login-form to GitHub.


4. Enter your GitHub credentials (if prompted)

If it’s your first time pushing, Git may ask for your GitHub username and a Personal Access Token (PAT) instead of your password.

You can create one by visiting: 👉 GitHub Personal Access Tokens

5. Verify your changes on GitHub

After a successful push, go to your repository on GitHub — you’ll see your commits reflected there

You can also check the commit history:

git log

Common Errors and Fixes

Issue Cause Fix
error: failed to push some refs Your local branch is behind the remote branch Run git pull origin main --rebase before pushing again
authentication failed Invalid credentials or expired token Generate a new PAT and reauthenticate
remote: Repository not found Wrong remote URL Double-check the repo name and your GitHub username

:::tip

If you want Git to remember your remote branch for next time, you can use the -u flag:

git push -u origin main

Now, you can simply run:

git push

from then on — Git will automatically know where to push your changes.

:::

Summary

You’ve learned how to:

  • Understand what “push” means in Git
  • Connect a local repository to a remote one
  • Push your commits to GitHub
  • Handle common push errors

Need help? Ask your questions in the GitHub Discussions. We’re here to help you grow as a contributor