2

I am creating a new version of a project that I have no rights. Unfortunately I started making my changes (more than 20 local commits) and realized my mistake when I wanted to push my changes.

For example I am working with ProjectA on branch local with the unpushed, local commits, can I transfer the entire local branch to a new ProjectB as master?

I know that I can just contact the developer of the original project to give me temporary rights to solve my problem. However I am curious if there is an existing way to do this with just Git commands.

I have already found:

Community
  • 1
  • 1
B314005
  • 53
  • 9

3 Answers3

5

Just alter the push target.

git remote set-url origin https://github.com/username/ProjectB.git
Tatsuyuki Ishi
  • 3,883
  • 3
  • 29
  • 41
1

Create a new empty repository (say, projectB). Then add a new remote (say, projectb) with the URL of projectB into your projectA.

 $ git remote add projectb <projectB-url>      # add a new remote called 'projectb' with the url of project 'projectB'

Now Push your projectA repo's local branch commits/changes to projectbB repo's master branch.

$ git checkout local         # make sure you are in 'local' branch
$ git push projectb master
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
1

It seems you still want to make contribute for the origin github repo. So you can fork this repo and then push your local changes to the fork repo by:

git remote add fork <URL for the fork repo> -f
git checkout local
git push fork master

Now the master branch of fork repo contains your local changes. You can create a pull request to merge your changes to original github repo.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74