Branches and merging
Remote repositories
Goal: Clone, pull and push to share work · 9 min
A remote is another copy of the repository, e.g. on GitHub, GitLab or a company server. The default name is origin.
git clone https://example.org/team/app.git # copy + set origin
git pull # fetch + merge new commits
git push # upload your commits
git push -u origin feature # first push of a new branch
git fetch # download without merging
git remote -v # list remotes
A good daily rhythm: pull before you start, commit in small steps, pull again before pushing. If someone pushed first, your push is rejected ("non-fast-forward") — pull, resolve conflicts if any, then push. Never use push --force on shared branches; it can erase others' commits.
Worked example: Rejected push
- Push is rejected: the remote has commits you don't have.
- Pull merges them into your branch.
- Now the push succeeds.
git push
# ! [rejected] main -> main (non-fast-forward)
git pull
git push