2

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

VSO
  • 11,546
  • 25
  • 99
  • 187
  • 2
    Yes, see http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide/816614#816614 and http://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging – Marc K Jun 08 '15 at 22:50
  • Thank you, I will come back and upvote the answers once I meet the minimum rep requirements. – VSO Jun 08 '15 at 22:59

1 Answers1

4

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).

Community
  • 1
  • 1
Zac Thompson
  • 12,401
  • 45
  • 57
  • I really needed the branchname part of "git push -u branchname," that wasn't in my notes - thank you. What does the "-u" do? We are switching to pull requests, so I will need to push it. – VSO Jun 08 '15 at 23:09
  • 1
    The `-u` sets the remote branch (in this case, `origin branchname`) to be the "upstream" for your local branch. This means that future 'git pull' or 'git push' for your local branch will be able to infer the upstream branch. – Zac Thompson Jun 15 '15 at 21:58