How do I create my own Git branch to work on?

1.1k views Asked by At

My goal - to branch of from our development branch to be able to work on it separately. I was quickly shown how to do this as:

  1. Open git shell or powershell/cmd and navigate to the folder where the project resides.

  2. Run "git branch (desiredNameForMyBranch)". From what I understand this just creates a local branch.

  3. Run "git checkout (desiredNameForMyBranch) - this switches to the branch locally?

  4. Run "git push origin" - this creates the branch remotely?

Is this correct? (We are using github, but it's all the same git, right?). And yes, I realize I need to take a course on this on pluralsight or something, I just don't have four hours today to do it.

This is similar to what I need, here for reference if other people have the same q later: https://github.com/Kunena/Kunena-Forum/wiki/Create-a-new-branch-with-git-and-manage-branches

1

There are 1 answers

2
Zac Thompson On BEST ANSWER

You can do steps 2 (git branch) and 3 (git checkout) at the same time with git checkout -b branchname

For step 4, I am accustomed to git push -u origin branchname to explicitly create the branch remotely and set it as the upstream for your working branch. This lets you do git pull later without arguments to update your working copy from the remote branch. See How do I push a new local branch to a remote Git repository and track it too?

However, you can skip step 4 if you are only doing some short-term local development, depending on your group's chosen workflow. Local-only branches are commonplace + disposable (not replicated).