6 ms·
I think the author meant these commands as I'm in the same OS class and this script has been circulating around the class: $ cat git-create-branch #!/bin/sh
by wmcc 17y ago
I think the author meant these commands as I'm in the same OS class and this script has been circulating around the class:
$ cat git-create-branch
#!/bin/sh
if [ $# -ne 1 ]; then
echo 1>&2 Usage: $0 branch_name
exit 127
fi
branch_name="$1"
git push origin origin:refs/heads/${branch_name}
git fetch origin
git checkout --track -b ${branch_name} origin/${branch_name}
git pull
- theli0nheart 17y agoWow...just wow. Why would you do this to yourselves? First of all, git push origin origin:refs/heads/${branch_name} is totally unnecessary when creating a new branch. I see that there are remote branches you want to track. It's simple, no need for a script. Just make sure you are synced with the current version of the repo you are using (using `git pull`). Then: git checkout --track -b bugfix origin/bugfix Easy as pie. I even have an alias set when I want to do this, so I just call git cot bugfix origin/bugfix To create a new branch locally (that doesn't track a remote), just call git checkout -b new-feature Note: When using `git pull`, `git fetch` doesn't need to be called. Pulling changes will fetch them for you automatically.
- davidw 17y agoThat's not simple. Simple would be doing what everyone wants it to do with one command that's really easy to remember/discover.
- pyre 17y ago> Simple would be doing what everyone wants it to do with one command Everyone comes to the plate with different experiences/expectations. You can't hope to satisfy everyone.
- jshen 17y agohow could it be simpler?
- tghw 17y agohg branch new-feature If you want it to branch from a different changeset than the one you're on, then: hg update deadbeef hg branch new-feature No flags, no orgin/newfeature (what does that even mean?), just the commands describing exactly what you're doing.
- jshen 17y ago# this creates the branch and switches to it (i.e. does a checkout) git checkout -b new-feature The only diff is -b, which is fine to me because it makes it clear that you are doing two things. You don't need the origin/newfeature stuff for the common case. I'm assuming this is what 'hg branch new-feature' is doing. How do you create a branch and not switch to it?
- tghw 17y ago> How do you create a branch and not switch to it? hg branch new-feature hg update default But why would you not want to switch to a branch you just created? Why create the branch if you're not going to work on it?
- jshen 17y agoI don't presume to know what is necessary by everyone's situation. If the argument is that mercurial is better because you don't have to use -b, well that's weak sauce.
- davidw 17y agoI actually use git, myself, but it's not just the -b; there's all kind of stuff like that in git's "user interface". It gets annoying at times.
- davidw 17y agoAlso, while it makes it 'a bit annoying' for people like me, I wonder if it will rule git out when it comes to Big Companies and people who are not so computer literate. The last time I looked at the git/windows thing, it was pretty ugly and not nearly as easy to use as turtlesvn.
- SlyShy 17y agoThat's a very odd and circuitous way of doing something that is already built-in, I've got to say.