DZone
DevOps Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > DevOps Zone > Updating Local Git Repos When Upstream Moves

Updating Local Git Repos When Upstream Moves

So, the upstream remote that your Git instance is pointing to has changed. How are you supposed to correct this situation?

Lorna Mitchell user avatar by
Lorna Mitchell
·
Jan. 10, 17 · DevOps Zone · Opinion
Like (1)
Save
Tweet
4.62K Views

Join the DZone community and get the full member experience.

Join For Free

The scenario: the "main" repository of a Git project has changed. Either an organization rebranded, a project got a new maintainer, or a fork became the acknowledged master. In Subversion, this was the svn switch command and Git has an equivalent. It's relatively easy in git to change your upstream once you know how, so don't be tempted to just delete your local repo and re-clone! We can do better than that.

Your local repo keeps a list of "remotes," or other copies of the repository that it knows about. To list all the remotes you have and which URL they point to, use this command:

git remote -v

Look at the list and work out which remote(s) need to update to a new URL. The first column is the remote name, and the second is the URL where the repo exists (you will see them all twice, one labelled "fetch" and one labelled "push;" this allows us to have different read and write endpoints for the same remote name but in practice is vanishingly rarely used, so just try to ignore the duplication for the purposes of this maneuver).

First, delete the remote that points to the old location, so if the remote you want to change is called "upstream" then the command would be:

git remote remove upstream

Next, we need to create the new remote. Get the URL of the repo (copy it from the GitHub page, or whatever works for the hosting system you use) and create the new "upstream" repo like this:

git remote add upstream [paste url here]

Note: Git does not actually check that you've supplied information that will work at all! It might be worth following up with a git fetch upstream to confirm that you can communicate with the repository as expected.

All these settings are in Git's .git/config file in a fairly easy format, so you can also go there to make changes (especially handy if you need to update a lot of remotes for some reason). Hopefully, if you do come across this fairly unusual situation, the information here helps you to get back up and developing quickly.

Git Upstream (software development)

Published at DZone with permission of Lorna Mitchell, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Are All Kubernetes Ingresses the Same?
  • C++ Creator Bjarne Stroustrup Interview
  • The Importance of Semantics for Data Lakehouses
  • Understanding Kubernetes Resource Types

Comments

DevOps Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo