2009/1/4 Alexandre Dulaunoy <adulau@xxxxxxxxx>: > On Fri, Jan 2, 2009 at 4:28 AM, Karl Chen <quarl@xxxxxxxxxxxxxxx> wrote: >> >> How about an option to git-branch that just prints the name of the >> current branch for scripts' sake? To replace: >> >> git branch --no-color 2>/dev/null | perl -ne '/^[*] (.*)/ && print $1' > > I tend to support your request especially that extracting the current > branch is something that is done regularly. Looking in my own scripts/aliases > and some of my colleagues, there are plenty of variation using Perl, > sed, awk, tr > and Python to extract the current branch. > > Using git-symbolic-ref is not obvious, especially that the summary/name > of the man page is : > > "git-symbolic-ref - Read and modify symbolic refs" > > But the description is pretty clear : > > "Given one argument, reads which branch head the given symbolic ref refers to > and outputs its path, relative to the .git/ directory. Typically you > would give HEAD > as the <name> argument to see on which branch your working tree is on." > > But naturally, as a lazy user, you will pick git-branch especially > that's the tools is listed > with the most commonly used git commands with a very attractive description : I dont think it has to do with lazyness. It has to do with the fact that parsing git branch gives you a branch name that you can use an an argument to many other git commands. Whereas git-symbolic-ref doesnt. It requires additional post-processing that unless you are very git aware is not at all clear. Like for instance in this thread the recommendation is to use sed like this: git symbolic-ref HEAD|sed s,refs/heads/,, however, that makes me think "how do i do that on a windows box? does the presence of git on a windows box mean that they will necessarily have sed available? Can i rely on that? Can i rely on the sed rule being sufficient? And what happens with this command if im not on a branch at all? Well it turns out that git symbolic-ref HEAD *dies* with a fatal error on this command. SO it probably should be: git symbolic-ref HEAD 2>/dev/null|sed s,refs/heads/,, but now its even less portable. Even if sed is available on windows /dev/null isnt. Id very much like a proper way to find the usable form of the branch name as it would make a lot of thing easier. In particular requiring people use pipes means that there is a portability issue with scripts. How does one make this happen on a windows box for instance? Id also very much like a way to find the "upstream" for a branch. IOW, id very much like to know where I will push to if i issue a "git push" command, or what i will merge if i do a git pull. There doesnt seem to be an easy way to find this out currently. And its very useful information. Im coming from the point of view of someone trying to make the perl build process a bit more "git aware". Unfortunately Perl has to build out of the box on so many platforms that unix-centric tricks like huge command pipes arent very helpful. They immediately fall down when you start dealing with oddball platforms like Windows and VMS. Yves -- perl -Mre=debug -e "/just|another|perl|hacker/" -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html