What's a remote?¶
Suppose you're working on a software project with a friend. Presumably, each of you have your own isolated development environments. So, how do you and your friend share updates to the codebase?
A remote is a centralized place for you and your friend to upload and download changes to the commit graph, so that your code stays "in sync".
How does it work?¶
What if I accidentally make changes that conflict with the remote?¶
For example, suppose your local commit graph matches the remote's commit graph.
Then the main branch on the remote receives a new commit.
Around the same time, you make a separate commit to main in your local repo.
Now your commit graph is misaligned with the remote. (Git would say that your local commit graph has diverged from the remote.)
This scenario should be avoided!
If each developer works on a separate branch (not main), they don't have to worry about their commit graphs becoming misaligned like above. Typically each developer will push their branch changes to the remote when ready, and the changes will be merged into main on the remote.
Each developer should periodically pull the main branch into their local repo and adjust their feature branches accordingly to stay up to date.
How do I create a remote?¶
There are lots of ways, but perhaps the most common method in practice is to use Github.
What is git clone
?¶
git clone
is used to download a remote repository to your local machine. Use git clone
if
- The remote repo already exists and has commits
- You haven't set up a local version of the repo
A common scenario for this is..
Suppose Bob has been working on project X for some months. Now Carrie wants to get involved in the project. Carrie should clone the remote repo to her local machine.
Cloning is something you do once. After you've cloned a remote, you should use git fetch
or git pull
to stay in sync.
What's origin
?¶
origin is just a common name people use to reference their remote . You can rename the remote, if you'd like .
Can I have multiple remotes?
Yes! Git is designed with a distributed architecture in mind.