47
loading...
This website collects cookies to deliver better user experience
$ git clone [email protected]:googleapis/python-tasks.git python-tasks/main
git branch ${branchName}
or git checkout -b ${branchName}
. I'll do it with worktree while i'm in the main branch folder.$ git worktree add -b my-awesome-branch ../my-awesome-branch main
../
If you forget it you will end up putting the branch in the folder where main lives and that can get real ugly, real fast. ~/Projects
/python-tasks
/main
/my-awesome-branch
$ git worktree list
~/Projects/python-tasks/main 63df2ef [master]
~/Projects/python-tasks/my-awesome-branch 63df2ef [my-awesome-branch]
$ git worktree add --track -b add-appengine-flexible-tasks-samples ../ppr-review origin/add-appengine-flexible-tasks-samples
Preparing worktree (new branch 'add-appengine-flexible-tasks-samples')
Branch 'add-appengine-flexible-tasks-samples' set up to track remote branch 'add-appengine-flexible-tasks-samples' from 'origin'.
HEAD is now at e2c8eee chore: generate noxfile.py for samples
git worktree add
: We've seen this. Its the base command to create a branch and a working tree--track
: This sets up tracking mode. We need it to track a remote branch-b
: This will create a new branch and we give it the same name as the remote branch because its the right thing to do. But really we could call it anything.../pr-review
The path we want it checked out to. Don't forget that ../
origin/add-appengine-flexible-tasks-samples
Finally the <remote>/<branch>
that we want check out.git worktree list
We'll see our friends branch in our working tree ready for review.$ git worktree list
~/Projects/python-tasks/main 63df2ef [master]
~/Projects/python-tasks/my-awesome-branch 63df2ef [my-awesome-branch]
~/Projects/python-tasks/pr-review e2c8eee [add-appengine-flexible-tasks-samples]
main
is$ git worktree remove pr-review
rm -rf ./pr-review
. This is bad. I just broke my working tree. The folders gone but git still knows about it when I do git worktree list
How can we fix this? Is it time to just throw the whole repo away and clone again? What do we do?$ git worktree prune
$ git worktree add -b emergency-fix ../temp main
$ pushd ../temp
# ... hack hack hack ...
$ git commit -a -m 'emergency fix for boss'
$ popd
$ git worktree remove ../temp