As a programmer, one of the best things that has happened to me is Git!
Git allows you to keep your code in sync with a remote repository that is shared with your team members.
When you run the command 'git init', you are creating a Git repository on your local machine. The purpose of this repository is to keep your code changes organized and ready to be synchronized with a remote Git repository. To sync your code changes with a remote repository, you need to specify the location of the remote repository.
The first step is to add remote repos to your project.
# Syntax to add a git remote
git remote add REMOTE-ID REMOTE-URL
By convention, the original/primary remote repo is called the origin. Here’s a real example:
# Add remote 1: GitHub.
git remote add origin firstname.lastname@example.org:example/example1.git
# Add remote 2: BitBucket.
git remote add upstream email@example.com:example/example2.git
In the above example, we add the remote repository of a project. Use the above command to add one or more remote Git repos(using your project URL) – make sure that each repo has its Remote ID, i.e. origin, upstream in the above example.
If you want to view a comprehensive list of all the remotes, you can do so by using the following command:
$git remote -v
origin firstname.lastname@example.org:jigarius/toggl2redmine.git (fetch)
origin email@example.com:jigarius/toggl2redmine.git (push)
upstream firstname.lastname@example.org:jigarius/toggl2redmine.git (fetch)
upstream email@example.com:jigarius/toggl2redmine.git (push)
If you no longer need a remote you added, you can remove it by following these steps:
# The syntax is: git remote remove REMOTE-ID
git remote remove upstream
Note: In my case, it's Upstream, but it will be your remote-id; it could be anything you specified such as origin, origin2, etc.
Synchronizing code across multiple Git repositories and pushing it to multiple remotes is a straightforward process that can be quite useful when managing mirrors or copies of the same repository.