问题
Being very new to git, I'm trying to get an overview of how to use multiple work directories for different branches off one github project. In particular I want/need to work on two branches - one the 'master' the other one a maintenance release, say maintenance/project1. The plan is to run the work under Linux/Mint 17.2. As well, I would like to make use of the latest git worktree features introduced in 2.5.
Assuming I have a github account, have forked my own fork off the main project and have cloned the fork to my local machine in ~/user/myproject.
As things stand now, I don't expect to contribute code via git push, all the results of my work & testing will be passed on to others for possible fixes via e-mail - doing it via git might be nice down the road, but won't be necessary to start.
What I see as the steps I would need a corresponding set of git commands for are:
- Creating the two work tree
- Switching between these trees
- Keeping both trees up-to-date with the upstream master
- any other cautions/ special considerations for working this way.
回答1:
Creating the two work trees
git clone https://github.com/someone/someproject.git
(this will give you directory
someproject
on themaster
branch)cd someproject; git worktree add ../someproject-devel devel
(this will give you directory
someproject-devel
on thedevel
branch, assuming such a branch exists)
Switching between these trees
Just use the cd
command.
Keeping both trees up-to-date with the upstream master
Just cd
in the appropriate directory and run git pull
. Doing this in the main working tree first may be best, but is not required (the man page does not address this specifically, and I haven't looked into the worktree implementation in detail. If an issue existed it would only be one of optimal use of space, not functionality).
any other cautions/ special considerations for working this way.
From the man page:
Multiple checkout in general is still experimental, and the support for
submodules is incomplete. It is NOT recommended to make multiple
checkouts of a superproject.
来源:https://stackoverflow.com/questions/32193360/work-flow-for-using-git-2-5-for-multiple-work-directories-using-git-worktree