Skip to contentSkip to conversation

How to jump between two repositories ...

DISCUSSION g2 6 participants 10 messages Jun 15, 2016

lore
Share & tools
lore

g2

author
#0 lore raw

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.

#1 lore raw
Quoted 7 lines · g2 <[email protected]> wrote:

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

Signature · 1 line
Shawn.
#2 lore raw
In reply to g2
Quoted 14 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

Quoted 5 lines

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....

Quoted 11 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.

#3 lore raw
Quoted 17 lines · J. Bruce Fields
Quoted 10 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

Quoted 5 lines

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

Quoted 9 lines

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

Quoted 3 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.

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.

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
author
#4 lore raw

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?

Quoted 14 lines · Andreas Ericsson

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.

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#5 lore raw

post
top-
don't
Please

Quoted 3 lines · g2 wrote:

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.

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#6 lore raw
In reply to g2
Quoted 18 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

Quoted 7 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.

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ö

author
#7 lore raw

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?

Quoted 54 lines · Väinö Järvelä
Quoted 18 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

Quoted 7 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.

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ö

#8 lore raw
Quoted 6 lines · On Dec 5, 2007, at 08:44, g2 wrote:

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ö

#9 lore raw
In reply to g2
Quoted 1 line · On Dec 4, 2007, at 10:44 PM, g2 wrote:

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