7. Remotes and GitHub

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.

Run in Terminal:
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.

Task

Push your local commits to the GitHub repository.

If the push was successful, you should see something like this in your terminal:

Result:

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.

Run in Terminal:
git pull origin main
Task

Pull the latest changes from GitHub.

Great! To recap, this is the basic workflow when collaborating on a project using GitHub:

  1. Pull the latest changes from the remote repository.
  2. Make your changes locally.
  3. Commit your changes.
  4. Push your changes to the remote repository.

Of course, there's a lot more to collaborating on GitHub, such as branching, pull requests, and handling merge conflicts. But this is a good starting point!

Next step
© 2024-2025 GitByBit.All rights reserved.