git/list[1] front-page[2] threads[3] people[4] search[5] about
 

example of git-p4 usage: checking out remote branches?

From
Cchristopherlmarshall@yahoo.com <christopherlmarshall@yahoo.com>
Date
Feb 23, 2009, 16:30 UTC
Message-ID
<4431fe90-a540-4b19-954f-78465ef91eb2@e18g2000yqo.googlegroups.com>

I am trying to learn how to use git-p4 to clone a perforce depot with multiple branches to a git repo, push git changes back to p4, and pull p4 changes into a git repo.

I have written a bash script that executes a scenario like this end-to- end.

I am wondering if the commands I am using make sense or if they are missing the point of git-p4; is my approach absurdly cumbersome?

In particular, should I really be checking out a remote branch, then creating a local branch from it to work with?

I'm attached my bash script below.
Chris Marshall

#!/bin/bash # file_summary: git-p4 clone, illustrates importing p4 repo, git -> p4 changes, and p4 -> git changes

rm -rf server workspace mkdir -p server workspace git-proj CWD=$(pwd)

# start server cd server p4d -f -p 1666 & p4pid=$! disown $p4pid

# cd ../workspace export P4PORT=1666 export P4CLIENT=testws export P4EDITOR=true

# create client while ! p4 client -o > tmp.txt ; do sleep 1 done p4 client -i < tmp.txt

# create some files in the mainline of a project mkdir -p proj1/main cd proj1/main echo "1" > f1 echo "2" >> f1 echo "3" >> f1 echo "4" >> f1 echo "5" >> f1 p4 add f1 p4 submit -d "initial checkin" sleep 2

# create a branch
(
   echo "Branch: main2br1"
   echo "View:"
   echo "   //depot/proj1/main/... //depot/proj1/br1/..."
) | p4 branch -i

p4 integrate -b main2br1 p4 submit -d "created br1 branch" sleep 2

# change main line p4 edit f1 echo "1" > f1 echo "2" >> f1 echo "3" >> f1 echo "4" >> f1 echo "4.1" >> f1 echo "5" >> f1 p4 submit -d "4.1 -> f1 on main line" f1 sleep 2

# change branch cd ../br1 p4 edit f1 echo "1" > f1 echo "2" >> f1 echo "2.1" >> f1 echo "3" >> f1 echo "4" >> f1 echo "5" >> f1 p4 submit -d "2.1 -> f1 on br1" f1 sleep 2

cd $CWD cd git-proj git-p4 clone //depot/proj1@all proj1 --detect-branches

cd proj1

# checkout the head of the remote branch git checkout p4/proj1/br1

# create a local branch to work with git branch br1 git checkout br1

# make changes echo "1" > f1 echo "2" >> f1 echo "2.1" >> f1 echo "2.2" >> f1 echo "3" >> f1 echo "4" >> f1 echo "5" >> f1 # commit git commit -a -m "2.2 -> f1 on br1"

# br1: submit back to perforce
(
   echo "y"
) | git-p4 submit

# p4 2.3 -> f1 on br1 cd ${CWD}/workspace/proj1/br1 p4 edit f1 echo "1" > f1 echo "2" >> f1 echo "2.1" >> f1 echo "2.2" >> f1 echo "2.3" >> f1 echo "3" >> f1 echo "4" >> f1 echo "5" >> f1 p4 submit -d "2.3 -> f1 on br1"

# pull them into git repo cd ${CWD}/git-proj/proj1 git-p4 sync //depot/proj1@all --detect-branches git merge p4/proj1/br1

# kill server kill $p4pid cd $CWD rm -rf workspace server git-proj

Message 1 of 1 in “example of git-p4 usage: checking out remote branches?”
  1. christopherlmarshall@yahoo.comFeb 23, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.