简体   繁体   中英

Git: how to change active branch on remote repository?

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?

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"

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM