You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
So far everything you have done has been local — changes stored only on your own machine. Remotes are copies of your repository hosted on a server such as GitHub, GitLab, or Bitbucket. Working with remotes is what enables collaboration and serves as your off-site backup.
When you clone a repository, Git automatically sets up a remote named origin pointing to the URL you cloned from. If you initialised a repo locally and want to connect it to a remote, add one manually:
git remote add origin https://github.com/you/my-project.git
git remote -v
This shows all configured remotes and their fetch and push URLs.
git push uploads your local commits to the remote:
# Push the current branch and set origin as the upstream
git push -u origin main
The -u flag sets the upstream tracking relationship. After this, you can simply run git push on subsequent pushes.
git fetch downloads new commits, branches, and tags from the remote without changing your working directory or current branch:
git fetch origin
This is safe — it only updates the remote-tracking references (like origin/main) and does not modify your local branches.
git pull is a convenience command that runs git fetch followed by git merge (or git rebase, depending on your configuration):
git pull origin main
Pull brings remote changes into your current branch. If both you and a collaborator have pushed to the same branch, pull may trigger a merge.
When you fetch, Git creates references like origin/main that represent the state of the remote branch at the last fetch. You can inspect them:
git log origin/main --oneline
To push a branch that does not yet exist on the remote:
git push -u origin feature/login
After a feature branch has been merged on the remote, delete it to keep things tidy:
git push origin --delete feature/login
git remote rename origin upstream
# Start by getting the latest changes
git pull origin main
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.