tags:

views:

60

answers:

3

Hi,

I am working on origin:abc remote repository . I want to update the origin:def repository in the remote repository in git. Can some please give me command for this?

A: 
git push origin def
Pat Notz
A: 

Say we have two repositories:

$ git init --bare abc.git
Initialized empty Git repository in /tmp/abc.git/
$ git init --bare def.git
Initialized empty Git repository in /tmp/def.git/

Now we do some work in a clone:

$ git clone file:///tmp/abc.git work
Initialized empty Git repository in /tmp/work/.git/
warning: You appear to have cloned an empty repository.
$ cd work
$ touch file
$ git add file
$ git commit -m file
[master (root-commit) 49cf67e] file
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file

Updating its origin (the abc repo) happens the usual way:

$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 201 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To file:///tmp/abc.git
 * [new branch]      master -> master

To push to the def repo, we can save future typing by adding a remote for it:

$ git remote add def file:///tmp/def.git

Now pushing is easy:

$ git push def master
Counting objects: 3, done.
Writing objects: 100% (3/3), 201 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To file:///tmp/def.git
 * [new branch]      master -> master

For a one-time push, the repository's URL would be suitable:

$ git push file:///tmp/def.git master
Greg Bacon
A: 

Do you mean the origin:def branch? I'm going to assume you have one remote repository, called origin. It has two branches: abc and def. You have a local branch called abc that you're making changes in. Instead of pushing the commits you have in abc to the remote abc branch, you want to push them to the remote def branch. To do this the command would be git push origin abc:def.

This may end up confusing you later, because the commits in your local abc branch will be pointed to by the remote def branch and the remote abc branch won't have your changes in them. As long as you can keep track of what and why you're doing this, there isn't problem doing this.

Xentac