Frank
Frank

Reputation: 31096

How to combine git checkout -b and git push origin?

I'm new to git, right now I do the following steps to create a local branch and push it to origin :

> git checkout master
> git checkout -b ABC
> git push origin ABC:ABC -u

I wonder if there is a command that can combine all the above into one line ?

Upvotes: 0

Views: 139

Answers (1)

djechlin
djechlin

Reputation: 60788

No. This is contrary to the philosophy of what a remote (branch, server, etc.) is. You do your work locally, then push it. If you want to do your work on the server, then... log into the server and do it locally.

This really isn't an operation you should be doing terribly often. How often do you want a new branch on origin with no information in it? Yes, sometimes this is needed e.g. for creating a "production" branch, but I can't help but think you have a bad design if you need to do this sort of thing more than O(1) times per project. You probably want to do work on that new branch first. But of course, if you feel differently, you can script it yourself, either in bash or via git alias.

That all being said, github does support creating a branch directly on their server: https://github.com/blog/1377-create-and-delete-branches

Your question is arguably a duplicate of How do you create a remote Git branch?.

Upvotes: 2

Related Questions