threads / discuss / 11136

How to jump between two repositories ...

Subject: How to jump between two repositories ...

## tl;dr

10 messages between Dec 5, 2007 and Dec 5, 2007.

replies: 9people: 6as markdown or json

g2· Dec 5, 2007, 05:59 UTC · lore
Hello all,

I am currently working on some code at the office that I also want to work with at home. Seems like a good candidate for git. So I created a repository at work and did a "git clone" at home. I've run into some strange behaviour that I don't understand and would appreciate if someone can clarify for me.

Imagine this scenario. At work: git init edit test.c git add test.c git commit

Then at home: git clone <work git url> edit test.c git commit -a git push

At this point, I wanted to push my changes back to my work repository so I can continue work the next day. So at home, I did a git push. I expect that my work repository has the newest material, but I find that when I do "git status" at work the next day, it tells me that my test.c is "modified" and has already staged it for commit. I need to do a "git reset" followed by "git checkout" to update my work folder to the latest stuff.

Totally different from my expectation of the repository knowing that it is out of date and then kindly suggesting that I should do a "git update" of some sort. What piece of understanding am I missing to properly "get" what is going on here, and how am I supposed to properly work with this setup?

Thanks for any help. Gerald.

Shawn O. Pearce· Dec 5, 2007, 06:11 UTC · re: g2 · lore

Re: How to jump between two repositories ...

g2 <gerald.gutierrez@gmail.com> wrote:
Show 7 quoted lines
> At this point, I wanted to push my changes back to my work repository  
> so I can continue work the next day. So at home, I did a git push. I  
> expect that my work repository has the newest material, but I find  
> that when I do "git status" at work the next day, it tells me that my  
> test.c is "modified" and has already staged it for commit. I need to  
> do a "git reset" followed by "git checkout" to update my work folder  
> to the latest stuff.

Oddly enough, this question is asked so frequently that it is answered in the GitFaq on the GitWiki:

  http://git.or.cz/gitwiki/GitFaq#head-b96f48bc9c925074be9f95c0fce69bcece5f6e73
-- 
Shawn.
J. Bruce Fields· Dec 5, 2007, 06:14 UTC · re: g2 · lore

Re: How to jump between two repositories ...

On Tue, Dec 04, 2007 at 09:59:57PM -0800, g2 wrote:
Show 19 quoted lines
> Hello all,
>
> I am currently working on some code at the office that I also want to work 
> with at home. Seems like a good candidate for git. So I created a 
> repository at work and did a "git clone" at home. I've run into some 
> strange behaviour that I don't understand and would appreciate if someone 
> can clarify for me.
>
> Imagine this scenario. At work:
> git init
> edit test.c
> git add test.c
> git commit
>
> Then at home:
> git clone <work git url>
> edit test.c
> git commit -a
> git push

You'll be much happier at this point if you ssh into work and then git pull from home....

Show 11 quoted lines
> At this point, I wanted to push my changes back to my work repository so I 
> can continue work the next day. So at home, I did a git push. I expect that 
> my work repository has the newest material, but I find that when I do "git 
> status" at work the next day, it tells me that my test.c is "modified" and 
> has already staged it for commit. I need to do a "git reset" followed by 
> "git checkout" to update my work folder to the latest stuff.
>
> Totally different from my expectation of the repository knowing that it is 
> out of date and then kindly suggesting that I should do a "git update" of 
> some sort. What piece of understanding am I missing to properly "get" what 
> is going on here, and how am I supposed to properly work with this setup?
Git doesn't support pushing to any branch that's checked out somewhere.
--b.
Andreas Ericsson· Dec 5, 2007, 08:45 UTC · re: J. Bruce Fields · lore

Re: How to jump between two repositories ...

J. Bruce Fields wrote:
Show 38 quoted lines
> On Tue, Dec 04, 2007 at 09:59:57PM -0800, g2 wrote:
>> Hello all,
>>
>> I am currently working on some code at the office that I also want to work 
>> with at home. Seems like a good candidate for git. So I created a 
>> repository at work and did a "git clone" at home. I've run into some 
>> strange behaviour that I don't understand and would appreciate if someone 
>> can clarify for me.
>>
>> Imagine this scenario. At work:
>> git init
>> edit test.c
>> git add test.c
>> git commit
>>
>> Then at home:
>> git clone <work git url>
>> edit test.c
>> git commit -a
>> git push
> 
> You'll be much happier at this point if you ssh into work and then git
> pull from home....
> 
>> At this point, I wanted to push my changes back to my work repository so I 
>> can continue work the next day. So at home, I did a git push. I expect that 
>> my work repository has the newest material, but I find that when I do "git 
>> status" at work the next day, it tells me that my test.c is "modified" and 
>> has already staged it for commit. I need to do a "git reset" followed by 
>> "git checkout" to update my work folder to the latest stuff.
>>
>> Totally different from my expectation of the repository knowing that it is 
>> out of date and then kindly suggesting that I should do a "git update" of 
>> some sort. What piece of understanding am I missing to properly "get" what 
>> is going on here, and how am I supposed to properly work with this setup?
> 
> Git doesn't support pushing to any branch that's checked out somewhere.
> 

Yes it does. It just supports it badly. If there is a work-tree connected to the receiving repository and that work-tree is pristine, it would be safe and sane to write the newly pushed changes to the connected working tree.

We do all our integration fixups by pushing to repositories with work-trees, simply because it's ridiculously inconvenient to add the infrastructure to pull to those repos from each individual developer. In that scenario, pushing to a checked out branch is highly useful and perfectly safe.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
g2· Dec 5, 2007, 15:28 UTC · re: Andreas Ericsson · lore

Re: How to jump between two repositories ...

How do you safely push to the repository? Even if my receiving repository is pristine (the last command I do is a commit), after I push into it, some files in the work-tree are effectively out of date and git says so by thinking they are modified and staged for commit. My original set of example commands illustrates this. What set of commands do you use to avoid the problem?

On 5-Dec-07, at 12:45 AM, Andreas Ericsson wrote:
Show 19 quoted lines
>
> Yes it does. It just supports it badly. If there is a work-tree  
> connected to
> the receiving repository and that work-tree is pristine, it would be  
> safe and
> sane to write the newly pushed changes to the connected working tree.
>
> We do all our integration fixups by pushing to repositories with  
> work-trees,
> simply because it's ridiculously inconvenient to add the  
> infrastructure to
> pull to those repos from each individual developer. In that  
> scenario, pushing
> to a checked out branch is highly useful and perfectly safe.
>
> -- 
> Andreas Ericsson                   andreas.ericsson@op5.se
> OP5 AB                             www.op5.se
> Tel: +46 8-230225                  Fax: +46 8-230231
Andreas Ericsson· Dec 5, 2007, 16:19 UTC · re: g2 · lore

Re: How to jump between two repositories ...

post top- don't Please

g2 wrote:
Show 8 quoted lines
> 
> How do you safely push to the repository? Even if my receiving 
> repository is pristine (the last command I do is a commit), after I push 
> into it, some files in the work-tree are effectively out of date and git 
> says so by thinking they are modified and staged for commit. My original 
> set of example commands illustrates this. What set of commands do you 
> use to avoid the problem?
> 

Vanilla git-push, ofcourse. I just make sure to run "git reset --hard" in the receiving repo before using anything in it. Granted, it's "safe" because I know I never want to use any changes from those repos and not.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Väinö Järvelä· Dec 5, 2007, 06:20 UTC · re: g2 · lore

Re: How to jump between two repositories ...

On Dec 5, 2007, at 07:59, g2 wrote:
Show 25 quoted lines
> I am currently working on some code at the office that I also want  
> to work with at home. Seems like a good candidate for git. So I  
> created a repository at work and did a "git clone" at home. I've run  
> into some strange behaviour that I don't understand and would  
> appreciate if someone can clarify for me.
>
> Imagine this scenario. At work:
> git init
> edit test.c
> git add test.c
> git commit
>
> Then at home:
> git clone <work git url>
> edit test.c
> git commit -a
> git push
>
> At this point, I wanted to push my changes back to my work  
> repository so I can continue work the next day. So at home, I did a  
> git push. I expect that my work repository has the newest material,  
> but I find that when I do "git status" at work the next day, it  
> tells me that my test.c is "modified" and has already staged it for  
> commit. I need to do a "git reset" followed by "git checkout" to  
> update my work folder to the latest stuff.
Did you clone a bare repository and push to it?

Here is an excerpt from Git User's Manual: "Note that the target of a "push" is normally a bare repository. You can also push to a repository that has a checked-out working tree, but the working tree will not be updated by the push. This may lead to unexpected results if the branch you push to is the currently checked- out branch!"

So to push to your work repository, you should create an intermediary repository between the work and home repositories. You can create it by running: $ git clone --bare /git/work/ /git/work.git/

Then you clone normally from the bare repository and pushing to it works fine. After you have pushed your changes to the bare repository, you'll have to pull them to the work repository to get the updates, just like you would do with any public repository.

Another option would be to pull from your home repository to the work repository, if you can access your home computer from the work computer.

-- Väinö

g2· Dec 5, 2007, 06:44 UTC · re: Väinö Järvelä · lore

Re: How to jump between two repositories ...

What I am gathering from this is that I can use git in two ways: 1) as "just another svn" bare git repository, or 2) only pull and don't push, because push causes confusion. I'd be happy to only ever use pull, but I have one machine behind a firewall and can't pull. I can push to a bare git repository like the svn model, but then I would just use svn. What's the value of "push" then?

On 4-Dec-07, at 10:20 PM, Väinö Järvelä wrote:
Show 54 quoted lines
> On Dec 5, 2007, at 07:59, g2 wrote:
>
>> I am currently working on some code at the office that I also want  
>> to work with at home. Seems like a good candidate for git. So I  
>> created a repository at work and did a "git clone" at home. I've  
>> run into some strange behaviour that I don't understand and would  
>> appreciate if someone can clarify for me.
>>
>> Imagine this scenario. At work:
>> git init
>> edit test.c
>> git add test.c
>> git commit
>>
>> Then at home:
>> git clone <work git url>
>> edit test.c
>> git commit -a
>> git push
>>
>> At this point, I wanted to push my changes back to my work  
>> repository so I can continue work the next day. So at home, I did a  
>> git push. I expect that my work repository has the newest material,  
>> but I find that when I do "git status" at work the next day, it  
>> tells me that my test.c is "modified" and has already staged it for  
>> commit. I need to do a "git reset" followed by "git checkout" to  
>> update my work folder to the latest stuff.
>
> Did you clone a bare repository and push to it?
>
> Here is an excerpt from Git User's Manual:
> "Note that the target of a "push" is normally a bare repository. You  
> can also push to a repository that has a checked-out working tree,  
> but the working tree will not be updated by the push. This may lead  
> to unexpected results if the branch you push to is the currently  
> checked-out branch!"
>
> So to push to your work repository, you should create an  
> intermediary repository between the work and home repositories. You  
> can create it by running:
> $ git clone --bare /git/work/ /git/work.git/
>
> Then you clone normally from the bare repository and pushing to it  
> works fine. After you have pushed your changes to the bare  
> repository, you'll have to pull them to the work repository to get  
> the updates, just like you would do with any public repository.
>
> Another option would be to pull from your home repository to the  
> work repository, if you can access your home computer from the work  
> computer.
>
> --
> Väinö
>
Steven Grimm· Dec 5, 2007, 06:57 UTC · re: g2 · lore

Re: How to jump between two repositories ...

On Dec 4, 2007, at 10:44 PM, g2 wrote:
Show 6 quoted lines
> What I am gathering from this is that I can use git in two ways: 1)  
> as "just another svn" bare git repository, or 2) only pull and don't  
> push, because push causes confusion. I'd be happy to only ever use  
> pull, but I have one machine behind a firewall and can't pull. I can  
> push to a bare git repository like the svn model, but then I would  
> just use svn. What's the value of "push" then?

You can push. Just don't push to a checked-out branch. I do exactly what you're describing and it works fine. It looks something like this:

server% git checkout mybranch server% edit somefile.c server% git commit

laptop% git checkout mybranch
laptop% git pull
   (with a pull configuration that pulls server's mybranch into  
laptop's)
laptop% edit somefile.c
laptop% git commit
laptop% git push server mybranch:laptop/mybranch

server% git checkout mybranch server% git rebase laptop/mybranch

Presto, ready to go. The trick is to push into a branch that's different from the one that's checked out, then rebase on top of that on the remote side after the push.

Yeah, it'd be nicer if you could just push to the checked-out branch directly (and there are hooks to let you do that) but this is only slightly awkward and it's easy once you've done it a few times.

-Steve
Väinö Järvelä· Dec 5, 2007, 07:32 UTC · re: g2 · lore

Re: How to jump between two repositories ...

On Dec 5, 2007, at 08:44, g2 wrote:
Show 6 quoted lines
> What I am gathering from this is that I can use git in two ways: 1)  
> as "just another svn" bare git repository, or 2) only pull and don't  
> push, because push causes confusion. I'd be happy to only ever use  
> pull, but I have one machine behind a firewall and can't pull. I can  
> push to a bare git repository like the svn model, but then I would  
> just use svn. What's the value of "push" then?

I guess the value over svn, is in the excellent tools that Git provides (such as rebase, bisect and merging). And that you can develop offline and still retain the individual commits.

And you could use Steven Grimms solution, but I guess with that, you need to be careful to not leave your servers working tree on any of your laptop/ branch if you might push to one.

-- Väinö

← back to recent threads