问题
I worked on some code on a local branch and then I pushed it to a remote test repository with this command:
git push origin fix_vouchers:fix_vouchers
I'd like to change the active branch on that remote repository so that the other developers can test this code. Can I do this from my local environment?
回答1:
If the remote repository is just a sharing point, a bare repository, you'd be better off just communicating the branch having the code to the other developers.
In a later comment you however imply that the remote repository is a checkout served as a website. You should note that even if you pushed to the currently active branch, pushing doesn't automatically check out the HEAD of that branch.
If you don't have any shell access to the remote machine, I don't think it's possible to do what you want. If you have any influence there, you could ask to set up a post-receive hook to check out the new branch.
Of course, if you have ssh access, just
ssh remote.net "cd /path/to/repo; checkout fix_vouchers"
回答2:
My View. There is nothing called an active branch in remote. It is up to you to decide whether a branch is active or not.
Coming to your your scenario. You can make a push a new branch to remote called releaseCandidate or release or devBranch. And then tell everyone to use that as the testing/development branch.
But if your problem is like other developers are using some particular script to checkout , you may need to change that script.
回答3:
No you can't set the active branch on the remote bare repository with a local command.
The active branch is the one pointed to by HEAD. This is the branch some of git's commands view as the default branch for the repository, such as git clone <url> <name>
will checkout the default branch by default.
If you have command line access to the remote repository, the git symbolic-ref
command can be used to set which branch is default -- see: Setting the default git branch in a bare repository.
That said, there is nothing special about any particular branch once checked out. Any branch can be shared with another developer by having them create a branch tied to the remote branch specifically with a git checkout -b <branch>
command, where is the name of the remote branch you want to share with them. This will create a branch on their local repository that is tracked against the remote branch.
来源:https://stackoverflow.com/questions/14275533/git-how-to-change-active-branch-on-remote-repository