3.3.8. Remote repositories
In order to share a project with the world, it needs to be pushed to a remote repository, hosted on a network or on the internet. To be able to push to a remote directory, first one must be made. To do so, run the command git add [shortname] [URL]
$ git remote add shortname git://path/to/new/repo
The shortname can now be used in lieu of the URL when referring to the remote repository.
Now a repository is added it is possible to print a list of remote repositories. This is done with the git remote command, passing the -v option to display the associated URL as well as just the shortname if desired. Even without adding a new remote repository, if the project was cloned it will list at least the repository it was cloned from.
$ git remote -v
repo-name git://path/to/new/remote-repository
origin git://path/to/original/remote-repository
If even this is not enough information running the git show [remote-repository] will list the URL as well as the branches Git is tracking for this particular repository.
In order to fetch data from remote repositories (for example, if someone working on the project has pushed new information to them), use the following command:
$ git fetch [remote-name]
This pulls down any and all information from this particular remote host that differs from what is on the local copy. Alternatively, running git pull will do the same from the repository the original copy was cloned from.
In order to share a project with a wider audience it needs to be pushed to a remote repository.
$ git push remote-repository branch-name
This command pushes the specified branch to the specified repository, but only if the user has write access. In the case of a conflict, pull the new work down first to incorporate it into the local version before pushing it to the remote repository.
Finally to rename a repository, run the git remote rename original-name new-name. Keep in mind that this will also change the remote branch names as well. Removing a repository is similar: git remote rm remote-name.