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

三世轮回 提交于 2019-12-03 03:31:49

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.

For creating new branch we will use: (using this command A new branch will create and the branch status will also change with newly created branch)

git checkout -b branch-name

And for pushing the changes we can run following commands:

git add . 
git commit -m "with meaningful comments" 
git push origin branch-name

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!