Git & Command Line•22 min read•Intermediate
Remotes, Push & Pull — Working with GitHub
How your local repo talks to a remote (GitHub, GitLab, Bitbucket) — and the PR workflow.
Remote = the cloud copy of your repo
A remote is just another Git repository, usually hosted somewhere others can access — GitHub, GitLab, Bitbucket. By convention the default remote is named `origin`.
bash
# Cloning an existing repo
git clone https://github.com/user/repo.git
cd repo
# Or, in an existing local repo, add a remote
git remote add origin git@github.com:user/repo.git
git remote -v # show remotes
git remote remove origin # if you typo'd the URLPush and pull
bash
git push # send your commits to origin
git push -u origin new-feature # first push of a new branch (sets upstream)
git pull # fetch + merge from origin
git fetch # fetch but DON'T merge (safer)
git pull --rebase # rebase your local commits on top of incomingThe pull request workflow
- 1. `git switch -c add-login` — branch for your feature.
- 2. Make changes, commit, `git push -u origin add-login`.
- 3. On GitHub/GitLab, open a Pull Request (PR) / Merge Request from your branch into main.
- 4. CI runs tests; reviewers comment.
- 5. You push more commits to address feedback.
- 6. Once approved, click Merge. Some teams squash-merge to keep main's history linear.
- 7. Delete the branch (locally and on the remote).
Resolving conflicts
When git can't figure out how to merge two changes, it leaves conflict markers in the files:
bash
<<<<<<< HEAD
your change
=======
their change
>>>>>>> origin/mainEdit the file to keep what you want (often a mix of both), remove the markers, then `git add` and `git commit` (or `git rebase --continue` if mid-rebase).
💡 Tip
VSCode and most modern editors highlight conflict markers and offer 'Accept Current / Incoming / Both' buttons. Use them; resolving conflicts by hand in vim is a rite of passage you can postpone.