Git -p4 and pull from other repositories

I have a laptop and desktop for which I am trying to learn how to use git to manage my work with a perforce repository. I am using git -p4 successfully on desktop and can use it successfully on laptop as well as isolated. However, one of the things I would like to do is "pull" or "push" changes from laptop to desktop, or vice versa, without first checking them out to the p4 branch synchronized with git.

So here's what I did to set up two repos: 1) set up a repo on my desktop using a git-p4 clone. Work on it, make a few commits to git, and a few go to git -p4. Everything worked as expected. 2) later, set up the repo on my laptop, getting it ready to work on both machines. Likewise, use git -p4 to make a clone of the current current p4 repo (now has a few checks in the past where I did git -p4 in (1).

Now what I was hoping to do: 1) do some work on the desktop. Commit work before git, but not p4. 2) go to your laptop, and do a git pull ... from the desktop repository. 3) continue my work on laptop, periodically switching to git. 4) (optional) transfer p4 from laptop 5) (optional) click on desktop (or drag from laptop to desktop) and continue to work on desktop, etc.

Basically, I would like you to be able to push / pull stuff between laptop and desktop without checking for p4.

Does this sound like something that should be possible? If so, are there any steps I am doing wrong above?

Something is happening here: when I try to "pull" in (2) above, I get error messages saying there are conflicts - and those conflicts are related to changes that were made between the first checkouts of the p4 branch, and the timing creating a second git -p4 repo. In other words, they seem to reproduce the changes that should have been in the code that the second repo contained, but for some reason they weren't.

I am new to git so hope my question is not crazy stupid or impossible to understand. Thanks in advance for any help you can give.

+2


source to share


1 answer


The problem is that your two repos (desktop and laptop) do not understand that they are linked to each other via Perforce. A normal git-p4

clone will be fetched from the top of the tree and thus you end up with different commit IDs for identical changes. This is because git "commit" includes information about its parents.

The simplest solution is as follows:

  • Create a clone of git -p4 on your desktop.
  • git clone

    from your desktop to your laptop.

Now your laptop and your desktop will share a shared history from Perforce. (You can check this by seeing that the commit IDs were different in the git log

past, but should be the same after these two steps.)



After this point, you should be able to push between the two repositories without conflicts.

In fact, you can git p4 sync

or git p4 rebase

anywhere because you git-p4

are smart enough to find other work and continue. Your laptop will also try to execute git pull

from the original server (your desktop), if possible, if I remember correctly.

Two other tips:

  • Do not use git push

    between these two repositories. It is usually unsafe to push to non-bare repos , i.e. Those repos that have working trees, such as the ones you described here. If you do a push like this, the index will be different from the working tree, and things like git status

    (and therefore, git commit

    etc.) won't work as you expect.
  • Keep Perforce on a separate branch (I use master

    ) and do all my development in theme branches. Pull on these branches only. When you execute git p4 sync

    or rebase

    , go back to the branch master

    . Then merge from master

    before your theme branch. This helps to keep the upstream history very clear and separate from the work you do in git.
+5


source







All Articles