DZone
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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. 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 · Opinion
Like (1)
Save
Tweet
Share
4.88K 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

  • How To Choose the Right Streaming Database
  • Testing Level Dynamics: Achieving Confidence From Testing
  • Microservices Testing
  • Using Swagger for Creating a PingFederate Admin API Java Wrapper

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • 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: