GitHub switch remotes in Visual Studio 2022

Kuler Master 246 Reputation points
2022-04-17T17:28:40.15+00:00

Hello,

I've recently downgraded from Pro to Free and now I can't manage to start pushing my source code toward the new organization repository.

What exactly I need to change in order to make it saving Git changes to the new FREE repository?

I removed the old origin and added new but then I started getting some errors every time I try to push.

Thank you so much!

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,695 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,380 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,131 questions
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 57,886 Reputation points
    2022-04-18T15:21:51.88+00:00

    you don't really specify your starting state. typically if you want to change remotes:

    1) commit local repo
    2) pull to get current with old remote
    3) create a new remote (bare if supported)
    4) change remote url to new remote
    5) push to remote (with force flags if not a bare remote).
    6) test pull

    with GitHub you can create a new remote via import of another repo. in this case the client just changes to the new remote

    you can check what you current remote is

    git remote -v

    you can change remote:

    git remote set-url origin https://github.com/user/repo2.git

    if you local does not have a remote, add:

    git remote add repo2 https://myname@github.com/myname/repo2.git

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 57,886 Reputation points
    2022-04-17T18:44:32.407+00:00

    Did you import the local repo to GitHub? How did you create the new GitHub repo?

    0 comments No comments

  2. Kuler Master 246 Reputation points
    2022-04-17T19:08:09.857+00:00

    Hello Bruce,

    Thank you for the prompt reply. Actually I created the new repo from within the GitHub website. Then I added it to Remotes and finally pushed the complete code to it using "Push to" option.

    Now I cannot push the new changes anymore. I keep getting different error messages.

    Thank you in advance for providing the exact steps to get rid of the old repo and start using the new one. It's much appreciated!

    0 comments No comments

  3. Bruce (SqlWork.com) 57,886 Reputation points
    2022-04-17T21:47:55.893+00:00

    make sure your in local repo everything is committed:

    git status

    create a empty GitHub repo
    add the remote to the local repo

    do a force push (because GitHub doesn't create a bare repo)

    git push -u -f origin master

    see:

    https://www.digitalocean.com/community/tutorials/how-to-push-an-existing-project-to-github

    0 comments No comments

  4. Kuler Master 246 Reputation points
    2022-04-18T05:22:12.78+00:00

    Hmm I am little confused about the second step which is adding the remote to the local repo.
    Namely I already have the .git directory in my project folder. Should I delete this folder and then initialize the new repo?

    0 comments No comments