Git: Efficient steps to create a new branch and push to remote

I figured out the steps but seems cumbersome, take bitbucket for example, suppose i already have a project called prj

  1. I branch a new project from server side(bitbucket.com), called prj-bz
  2. From local i add add a remote git remote add prj-bz https://blah...
  3. At the same time from local i create a new branch called prj-bz
  4. From local i call git push prj-bz prj-bz to let local repo and remote one connected.

I checked out some git books but seem none cover this.
Any more efficient way to do this?

  • Rollback Commit Upon Build/Test Failure on Jenkins
  • How to create pull request for wiki of a repository on Bitbucket?
  • 2 local folders, each containing a different branch of the same repository
  • is Bitbucket Repository, --bare or no?
  • Atlassian Bamboo: Handling git-Flow hotfix-branch
  • Cloning a repo at bitbucket.org
  • Enforce --recurse-submodules=on-demand for all clones of a repo
  • Feature branches in mercurial
  • Git: cloning with shared local storage (using hard links)
  • git index.lock File exists when I try to commit, but cannot delete the file
  • Revert after merge --squash
  • How to hide team activity lines on Visual Studio 2015?
  • 2 Solutions collect form web for “Git: Efficient steps to create a new branch and push to remote”

    Generally, people usually do one or the other Fork or Branch. It sounds like you are making a Fork of a repo, then making a branch in the fork with the same name. If you’re using a Pull Request to put data back in to the main repo, you don’t need to do both. Pick one of the two workflows:

    • Fork the repo on Bitbucket (or other site)
    • Clone the repo git clone https://bitbucket.org/username/repo-fork.git
    • Work in that fork git commit -m "some work done", git push -u origin master
    • Create a Pull request to request your changes to be placed back into the parent of the fork

    OR

    • Clone the main repo git clone https://bitbucket.org/username/repo-fork.git
    • Create a new local branch git checkout -b my-branch
    • Work in that branch git commit -m "some work done"
    • Push up the branch git push -u origin my-branch
    • Create a Pull request

    With the branch method, I’m assuming you have rights to write to the main repo. If not, you’ll want to stick to the fork method. There are more workflows out there too. Bitbucket also has a doc explaining this as well as one on Atlassian’s website with a bit more depth on Git workflows.

    Well, if creating a new repo instead of a new branch in an existing one, you could just git clone https://blah <target folder> to replace steps 2-4.

    If not, your only real alternative is creating a simple script that accepts remote name, branch name and git url as arguments and executes steps 2-4 with that information.

    Git Baby is a git and github fan, let's start git clone.