KiritoLyn
KiritoLyn

Reputation: 760

Pushing from existing local branch to new online repository

Basically what we have is master and testing-stage in our online repository.

I am currently connected to testing-stage and updated with my local. Now, the testing-stage has been merged with master.

Then what happened is that the testing-stage has been deleted manually on gitLab's website then a new repo was created and it was named test, it is identically to master which finished merging like mentioned above. Now I have done some changes and would like to checkout and push to test, but my current local repository is listening to the previous testing-stage which is now deleted. What is the best thing that I may do?

Upvotes: 2

Views: 117

Answers (3)

Clauz
Clauz

Reputation: 137

I suggest to cherry-pick your changes from your current branch to the master branch from test. That is:

  • change the remote URL:

    git remote rename origin oldorigin
    git remote add origin $test_url
    
  • give a new name to your current branch:

    git checkout -b mybranch
    
  • switch to the master branch and pull:

    git checkout master
    git pull -u origin master:master
    

    Now the local master branch should be synchronized with the master branch from the test repository.

  • cherry-pick your changes. For each of your new commits:

    git log mybranch # find id of your commit
    git cherry-pick $commit_id
    
  • finally, push to test's master

    git push
    

Upvotes: 1

Eldy
Eldy

Reputation: 1096

Given I understood your problem correctly...

Running git remote -v will allow you to see your remote URLs.

What you can do is remove the old remote URL pointing to the old repository:

git remote rm remote_name

I suspect the name will be origin.

Then you can add a new remote pointing to the new repository:

git remote add origin url_to_new_repository

You can also just add a new remote URL without removing the old one, in which case you will have two different remote URLs.

Upvotes: 2

veben
veben

Reputation: 22332

I would do like that:

  1. Clone test repository to have it locally
  2. Look at the modified files in testing-stage with git status
  3. Copy/paste all these modified files to the folder project of test repository
  4. Push the modification to remote test repository

Upvotes: 1

Related Questions