Kaigai Blog living abroad in my twenties

【My Study Note】Push and Pull

Infotech Web Developer

Push and Pull

Typing git status

git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean

What this means is that all the changes that you have on your local repository are currently ahead of what is stored in the remote repository on GitHub that ties into Git’s distributed workflow in which you can work in an offline state and then only ever communicate with a remote repository when you use the commands of git push or git pull.

How to push your changes to the remote repository

It’s always good practice to check which branch you’re currently on. You can use git status or git branch to do this.

This is important because if you do make changes in a different branch, you need to specify where you’re pushing up to.

Let’s push up the changes using the git push command.

git push origin main

In this example, I am specifying the origin branch to be the main branch. As in, I’m pushing my changes to the origin as the remote repository, and then I want to push it to this branch as the main.

Before the process is done, they’re taken the commit snapshots that I have in my local repository and pushed it up to the remote repository. Git has then compared those files with what’s on the remote repository to find any conflicts or problems.

If none are found, it’ll just merge them straight through, which is classed as an auto merge. If there are any conflicts, my push will fail.

Before doing a push, it’s also good practice to perform a git pull in order to get the latest changes from the remote repository and reduce the odds of encountering a conflict.

Git Pull

git pull

Normally when you’re working on a project, you could have several developers all submitting with different branches, different code, and different features. In order for you to get those changes, you need to use the git pull command.

With git pull, you’re taking all that data from the remote server. Git then merges the snapshot from the remote with the snapshot that’s on your local. It will auto merge them if there is no conflicts. Once that’s complete, you’ll have the latest changes on your local machine.