git create remote branch only (without local)
This question already has an answer here:
How to create a remote Git branch without creating a local branch?
One Solution collect form web for “git create remote branch only (without local)”
AFAIK, this isn’t possible. However, I would use alternative solutions (in ascending order):
If your client’s security policy allows it, make some api to the remote machine that would create a new branch, e.g. an HTTP PUT [*] request with authentication and the name of the new branch as a parameter. Then, you can access it via
curlor your favorite language, without needing a full-fledged ssh access.
Create an empty branch, so cloning will be very fast, even if the repo is large. E.g.:
git checkout -b empty git rm * git commit -m"create an empty branch" git push -u origin empty
You need to do it only once per repo. Then, when cloning, you can clone just this branch using the
git clone -b empty --depth 1 <repo>
Now you can create a new branch with the name you want:
git checkout -b <new-branch>
After a developer finishes working on a feature, the new branch can be updated by using the
git push -f origin <local-branch>:<new-branch>
Use a git hook on the client-side (i.e. the developer’s side), that will enforce the best practices, e.g.
pre-push. Assuming, of course, that your co-workers won’t ignore it 🙂
[*] or POST, but since you’re providing the name of the branch, it should be idempotent.