I'm cloning a repo that was first generated by git-p4. git-p4 uses a 'remotes/p4/master' branch that I would like to track. How do I tell git, which is cloning that repo, to track remotes/p4/master as well? That way I would be able to check out "origin/remotes/p4/master" or something.
You can adjust the fetching properties to mirror those references as well, although not as part of a standard clone.
So a sequence like:
git clone ~/p4/git/services/info-service.git
cd info-service
git config --add remote.origin.fetch +refs/remotes/p4/*:refs/remotes/origin/p4/*
git fetch origin
This will fetch refs/remotes/p4/release/1.1
for example in info-service.git
to be refs/remotes/origin/p4/release/1.1
in your clone, and you could create a branch based on it with git checkout -b r1.1-fixes origin/p4/release/1.1
Having said all that, in my Perforce replica repos, I create actual branches to mirror all the p4 remote branches, largely to avoid having to go through all the above. It also gives me a chance to fix up the naming from p4 path prefixes to git branch names (so p4/main
becomes master
, p4/release/1.1
becomes r1.1
etc). I use my own p4-to-git replication, but you could do much the same by looping over the p4 remote refs with git for-each-ref
and setting local branches using git update-ref
.