How to run git p4 submit on a bare repo?

TLDR

How does one run a git p4 submit on a bare repo? Which command line option to git p4 submit is that?

LONG STORY

I would like my team within my company, which uses perforce, to move to git. I want to use Git-P4 to achieve that. I want to have a section of perforce cloned to a git repo, and make that a remote repo, so that people would clone that, push changes to the remote repo and I would periodically resubmit the changes made in the remote repo back to the perforce. So I followed this tutorial

  • Take last N commits of the current branch and apply them to another branch
  • use git submodule with read-only access
  • git-svn rejected Basic challenge now that VPN is required
  • Replicate Gated check-in functionality in Visual Studio + VSO + Git
  • How can I choose to overwrite remote repository with local commits?
  • Git error: RPC failed; result=22, HTTP code = 404
  • http://answers.perforce.com/articles/KB_Article/Git-P4

    which boiled down to this command:

    git p4 clone //depot/path.to/folder@all folder --bare
    

    That works, then on my client machine I do

    git clone "user1@server:/home/user1/path/to/folder"
    

    and that’s fine and it shows up so I make an edit to a test file, then do the

    git add file
    git commit -m 'test'
    git push.
    

    and that works, but then back on the remote repo now in the folder with the repo, I do,

    git p4 rebase
    

    and I get this

    git p4 rebase
    Performing incremental import into refs/remotes/p4/master git branch
    Depot paths: //depot/path.to/folder/
    No changes to import!
    fatal: This operation must be run in a work tree
    Some files in your working directory are modified and different than what is in your index. You can use git update-index <filename> to bring the index up-to-date or stash away all your changes with git stash.
    

    and

    git p4 submit
    

    gives me this:

    Perforce checkout for depot path //depot/path.to/folder/ located at /home/user1/path/to/perforce.folder/
    Synchronizing p4 checkout...
    ... - file(s) up-to-date.
    fatal: Not a git repository: '.'
    Command failed: ['git', 'rev-list', '--no-merges', 'remotes/p4/master..master']
    

    So the problem is that the the git repo can’t be a bare repo when I do a submit, it has to be a regular one with a working directory, right? But if that’s the case, why even give me a --bare option? The reason I’m doing the --bare option is that when I left it out I got a different set of errors about uncommitted changes in the working copy of the remote repo. But how do I make the git p4 submit without any errors?

  • Merging two git repositories (accidentally downloaded .zip from github, need to merge back in)
  • showing git branch name in command prompt
  • Working in a git branch with submodules and commiting directly from that branch
  • Accidentally deleted the .git folder
  • Is my git workflow correct and in accordance with my team?
  • How to use the forked repo and still track updates from the original source
  • 2 Solutions collect form web for “How to run git p4 submit on a bare repo?”

    My understanding of git p4 is quite limited, but in theory this should work.

    To use git p4 in a way such that both your bare git repo and the perforce repos are synchronized, you would need to maintain at least 3 different types of repositories:

    • BareGitRepo – A bare repo that you’ve created. I would suggest not to use any git p4 commands in this repo directly. Just a regular bare git repo should be sufficient. All developers using git should be cloning this repository directly and pushing changes only into this repo as remote.
    • GitP4Repo A non-bare repo cloned from BareGitRepo, but to sync up with perforce. This is where you run all the git p4 commands.
    • P4Workspace – A perforce client workspace using which you can submit changes from the git repo to perforce.

    In the GitP4Repo:

    • Setup the repo initially using git p4 clone <PERFORCE_FILE_PATH>
    • Sync the changes from BareGitRepo regularly. (Something like git fetch origin && git rebase origin/master master)
    • Rebase changes from p4 regularly using git p4 rebase. (Which in essence does git p4 sync followed by a git rebase p4/master)
    • Submit the changes to perforce, using git p4 submit. This is where you would need the P4Workspace mapped in your client workspace.
    • Push the changes merged from perforce, back to BareGitRepo using git push origin master

    Gotchas I can think of:

    • These steps need to be run periodically (depending on how frequent you want the perforce commits to be synchronized with your git repo).
    • The git commit SHA1s will possibly change when you run a git p4 rebase since it turn invokes git rebase to overlay the commits from your git repo on top of the newer perforce commits. I’m not sure if there is an option to use git merge instead, and preserve the SHA1 hashes of the git commits.

    Finally to answer your question, why git p4 clone has a --bare option, I can only imagine that git-p4’s clone command tries to be similar to the regular git clone command.

    git clone also has a --bare option which is used to create a bare repository. And no, you cannot run a git pull or git checkout or git rebase on such a repository either.

    You can’t submit from a bare repo. A bare repo is only for cloning from and pushing changes to. If you want to submit you will need to clone the bare repo in another location.

    Why would you want a bare repo then? Well, it is used when you are hosting a git project that has a simple master repository that everyone pushes to. Usually the bare repo lives on a server that is not directly used by anyone. Keeping a ‘bare’ repo allows git to keep all of the data compressed as efficiently as possible. In many cases you might see 10:1 compression ratio compared to a single revision of a checked out repo.

    Git Baby is a git and github fan, let's start git clone.