2

So i have this scenario. I have 2 projects, P1 and P2. Also consider these projects have branches for ex: P1B1 and P2B1 (Project & Branch). I have want to push my local changes from P1B1 directly to P2B1 (Else creating a new branch and pushing to P2B2 is also fine. Please let me know if there is a simple way.

Mahesh
  • 129
  • 1
  • 2
  • 19
  • This is unclear - are P1 and P2 separate repos? If so, then why do you want to "push from P1B1 to P2B2"? – Oliver Charlesworth Dec 29 '17 at 17:12
  • Yes. Separate repositories. P1 is the usual repo which i created to start working on. P2 is more like a standard version of framework with a template. so i created a branch of P2 and migrated my existing code from repo P1. Now as i have completed all the migration and everything runs fine i want to merger P2 branch with P1 master. I know it's a bit messy but is there a way to get out of this ? – Mahesh Dec 29 '17 at 17:24
  • Is P1 the project which you are currently working on? Did you clone it from P2? – Code-Apprentice Dec 29 '17 at 17:59
  • Possible duplicate of [Git push existing repo to a new and different remote repo server?](https://stackoverflow.com/questions/5181845/git-push-existing-repo-to-a-new-and-different-remote-repo-server) – phd Dec 29 '17 at 19:16

2 Answers2

3

In the following, I assume that what you call "projects" are copies of the same code base, both of which are under version control and potentially have different changes and work occurring on their own branches. Git calls these "repositories". You can connect repositories to each other by creating remotes.

If P1 and P2 are repositories on different servers and you have a local repository on your own machine, you can create remotes for both of them:

$ git remote add p1 <URL to P1>
$ git remote add p2 <URL to P2>

Now you can interact with either repository with most git commands. For example, you can fetch all of the branches from both repos:

$ git fetch p1
$ git fetch p2

You can also push your current work on branch b1 to both of them:

$ git checkout b1
$ git push p1 b1
$ git push p2 b1

For more details, see Working with Remotes in Pro Git.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
1

According to the git documentation on git push (https://git-scm.com/docs/git-push) you can specify the repository and branch for a push

so a git push <R2 url> <branch name> (e.g. git push ssh://git@host.xz/path/to/P2.git/ B1

From the documentation:

repository: The "remote" repository that is destination of a push operation. This parameter can be either a URL (see the section GIT URLS below) or the name of a remote (see the section REMOTES below).

Info-Screen
  • 145
  • 10