-2

I want a yes or no answer to this one guys!

I've tried this command which the official Git documentation says should work, with respect to the question I am asking:

git checkout --track origin/my_branch_name

When I do this though, I get the following error:

fatal: Cannot update paths and switch to branch 'my_branch_name' at the same >time. Did you intend to checkout 'origin/my_branch_name' which can not be resolved as >commit?

FRUSTRATED BEYOND ALL BELIEF AS TO HOW HARD IT IS TO GET STRAIGHT FORWARD ANSWERS TO BASIC GIT QUESTIONS.

Just a simple yes or no PLEASE! NO complex explanations or, "oh I know, if you jump through these 50 hoops and ladders you can accomplish what you ask!"

I am simply asking if it is possible. If the answer is yes, please share the command that does this. THANK YOU...and sorry for being so upset. Reason why I am mad though...is because it seems to me like it SHOULD be the DEFAULT behavior for all branches created locally to ALSO be created on the remote repo so you can just push seamlessly without all the BS overhead. Doesn't anyone else feel the same or am I some kind of alien on this planet using Git? [end rant]

Cœur
  • 37,241
  • 25
  • 195
  • 267
Adam R
  • 31
  • 7
  • I would tell you why your feeling is not the same as others, but you've explicitly stated that you don't want explanations. – Jeremy Fortune Jul 15 '16 at 21:18
  • Also, what does "simultaneously" mean? Because `git checkout --track origin/my_branch_name` is not simultaneously doing anything. It's performing a bunch of steps. If you mean "in one line", then the answer is yes. – Jeremy Fortune Jul 15 '16 at 21:21
  • @jeremytwfortune, yes, by simultaneously I do mean "in one line", with one command, before the user hits the 'enter' key to send instructions to Git to do things. Now that Pierre supplied me with the answer I was looking for...I am now super curious as to why my feeling is not the same as others? The way I understand the words written in the Git documentation makes it seem like 'git checkout --track origin/my_branch_name' should create, both, a local and remote branch with the local one tracking the remote. Would luv 2 know at this point what I have misunderstood, if you care to help me still – Adam R Jul 19 '16 at 15:32
  • please ignore...testing the editor here: `git checkout --track origin/my_branch_name` ahhh, okay, I see how that works now :) – Adam R Jul 19 '16 at 15:43

2 Answers2

2

Yes.

Since you've indicated that you want a one-liner:

git checkout -b my_branch_name && git push -u origin my_branch_name
Jeremy Fortune
  • 2,459
  • 1
  • 18
  • 21
  • Ahhh, I see now. Okay, so while technically it is true that in one line, a person is able to do what I want with Git...Git does NOT support what I want with a single command (which is what I was trying to get at in my question, but alas did not have the correct word to describe my needs). So then I am even more confused. What is the Git documentation referring to when they say they have a 'shorthand' command = `git checkout --track origin/my_branch_name` ?? What is that command supposed to do then? – Adam R Jul 19 '16 at 18:13
  • From what I read, `--track` is a `branch` argument, not a `checkout` argument. Before you counter, note that `--track` only applies when using `git checkout -b my_branch_name --track origin/my_branch_name` and will not work without the `-b` flag. Using `--track` expands `git branch my_branch_name && git checkout my_branch_name` to `git branch my_branch_name origin/my_branch_name && git checkout my_branch_name`. In both cases, the remote branch must already exist. – Jeremy Fortune Jul 19 '16 at 18:36
  • I hear ya, but from the Official Git Documentation here: https://git-scm.com/book/en/v2/Git-Branching-Remote-Branches You can read the following: "The simple case is the example you just saw, running git checkout -b [branch] [remotename]/[branch]. This is a common enough operation that git provides the --track shorthand:" >$ git checkout --track origin/serverfix – Adam R Jul 21 '16 at 14:22
  • So was just trying to wrap my head around what they are specifically showing folks with that instruction in the documentation. Perhaps what the documentation shows is a lie? – Adam R Jul 21 '16 at 14:25
  • In any case, @jeremytwfortune, thank you kindly for helping me out here. I will def be using your trick of concatenating the commands to create a remote and local tracking branch in one go! Cheers for that!! – Adam R Jul 21 '16 at 14:27
  • I'll refer you to [this answer](http://stackoverflow.com/questions/10002239/difference-between-git-checkout-track-origin-branch-and-git-checkout-b-branch), which still requires that the upstream branch already exists. But there's a good discussion there. My version of git (2.4.5) doesn't work without the `-b`. Perhaps this is added in a later version. – Jeremy Fortune Jul 21 '16 at 16:25
1

No It is not possible to do all of these operations simultaneously, at least I have not been able to

Pierre
  • 1,329
  • 2
  • 12
  • 21
  • Thank you for the straight forward answer @Pierre! I can now stop trying to attempt to do all that with one command as the official Git documentation would have a poor soul like me believe. Thanks again!! – Adam R Jul 19 '16 at 15:00