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.