Setting up a git remote origin

Git

Git Problem Overview


I have the following repos.

  1. DEV REPO: in a directory on my development machine where i make changes
  2. MAIN REPO: bare repository on my development machine to which i push changes from dev repo
  3. PRODUCTION REPO: repository on host machine to pull updates from the main repo

I used git remote add origin /Users/me/sites/main_repo to set the MAIN repo as origin for the DEV repo. The PRODUCTION repo is on a remote host. Can i use a variation of the same command to set the MAIN repo as origin for the PRODUCTION repo also? If "yes", then i suppose the syntax would include an ip address. What would that look like?

Git Solutions


Solution 1 - Git

Using SSH

git remote add origin ssh://login@IP/path/to/repository

Using HTTP

git remote add origin http://IP/path/to/repository

However having a simple git pull as a deployment process is usually a bad idea and should be avoided in favor of a real deployment script.

Solution 2 - Git

For anyone who comes here, as I did, looking for the syntax to change origin to a different location you can find that documentation here: https://help.github.com/articles/changing-a-remote-s-url/. Using git remote add to do this will result in "fatal: remote origin already exists."

Nutshell: git remote set-url origin https://github.com/username/repo

(The marked answer is correct, I'm just hoping to help anyone as lost as I was... haha)

Solution 3 - Git

You can include the branch to track when setting up remotes, to keep things working as you might expect:

git remote add --track master origin [email protected]:group/project.git   # git
git remote add --track master origin user@172.16.1.100:group/project.git   # git w/IP
git remote add --track master origin http://github.com/group/project.git   # http
git remote add --track master origin http://172.16.1.100/group/project.git # http w/IP
git remote add --track master origin /Volumes/Git/group/project/           # local
git remote add --track master origin G:/group/project/                     # local, Win

This keeps you from having to manually edit your git config or specify branch tracking manually.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJayView Question on Stackoverflow
Solution 1 - GitClement HerremanView Answer on Stackoverflow
Solution 2 - GitlostphilosopherView Answer on Stackoverflow
Solution 3 - GitMichael ThompsonView Answer on Stackoverflow