Pushing and pulling changes from the remote repository
Now that we've connected our local repository to GitHub, we can start syncing changes between the two.
To send our local commits to GitHub, we use the git push command.
git push origin main
Here, origin
is the name of the remote, and main
is the name of the branch you plan to push.
If you're pushing changes for the first time, you may get a pop-up asking you to authenticate with GitHub. Enter your username and password (or token), and Git will remember it for future pushes.
Push your local commits to the GitHub repository.
If the push was successful, you should see something like this in your terminal:
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 8 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (12/12), 1.20 KiB | 1.20 MiB/s, done.
Total 12 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), done.
To https://github.com/yourusername/hello-world.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
Now, let's go to our GitHub repository and refresh the page. You should see all the files from your local repository, along with the commits!
Similarly, if someone else has made changes to the repository on GitHub, you can pull those changes down to your local repository with git pull. This will fetch the latest changes from the upstream branch and merge them into your local branch.
git pull origin main
Pull the latest changes from GitHub.
Great! To recap, this is the basic workflow when collaborating on a project using GitHub:
- Pull the latest changes from the remote repository.
- Make your changes locally.
- Commit your changes.
- Push your changes to the remote repository.
Hi! I'm Alex, creator of GitByBit.
This page is a part of the interactive course about Git version control.
It's a one-of-a-kind course that is integrated into the VS Code code editor. Learning directly in VS Code lets you operate Git exactly as you would in real life, doing real jobs, writing real code.
In addition, the course has access to your actual terminal, so it can point out mistakes, suggest workarounds, etc.
The course is FREE, there are no Ads or other bullshit. There are optional premium add-ons you can purchase, mainly to support my work (regrettably, I have to eat every day), but that's totally up to you.