Clone a repository and keep it synchronized
Clone a repository and keep it synchronized
A teammate joins a project that already lives on GitHub. Instead of creating a new empty repository, they clone the shared one so their local copy starts with its history and remote configuration.
What you’ll learn
- Clone a hosted repository.
- Inspect the configured origin.
- Use a branch-based synchronization loop.
Join an existing project
GitHub repo
Shared history already exists.
remoteClone
Create your local repository and working tree.
origin configuredBranch + push
Work locally and publish a topic branch.
feature branch
Clone creates a local repository with a configured remote
git clone copies repository data, checks out a working tree and normally adds the source as origin. Your local branches still remain separate from remote-tracking references.
A common daily loop is: fetch/pull before starting, make a branch, commit locally, push the branch, then open a pull request. When collaboration is busy, inspect incoming changes rather than treating pull as magic.
Clone, branch and publish your branch
Run this in a disposable practice repository unless the lesson explicitly says otherwise.
git clone https://github.com/OWNER/REPO.git
cd REPO
git remote -v
git fetch origin
git switch -c feature/readme
git push -u origin feature/readmeThe clone already knows origin. Creating a feature branch locally does not create a GitHub pull request; pushing publishes the branch so a pull request can be opened.
Practice: Clone and sync
Your task: Clone one of your disposable repositories into a second folder. Compare git remote -v and git log --all in both copies.
Common pitfall to avoid
Do not create multiple clones and assume their working files synchronize automatically. Each clone has its own local branches and must exchange commits through fetch/pull/push.
Check your understanding
Clone and sync: what to remember
Clone a repository and keep it synchronized is complete when you can explain the state being changed before you run the command, not merely repeat the syntax.
Read further: official supporting documentation.
Reaching the recap and completing the quizzes are separate milestones.