![]() ![]() Adding the "-a" flag will make sure remote branches are also included in the list.Listing your branches, by default, will only show your local branches' names. Provides more information about all your branches. It's the go-to command when it comes to managing any aspect of your branches - no matter if in your local repository or on your remotes. For the master, of course, is extremely similar.The "branch" command helps you create, delete, and list branches. So our regex would be ^\*?\s*main$ for the main branch. The words main or master can be matched with the literal words.The amount of whitespaces can vary, so we can use the * quantifier, leaving us with \s* Whitespaces can be simply a space or \s, the latter matching things like tabs and new lines also.So to match a possible *, the regex would be \*? In regex, a * is a quantifier, meaning "the thing before me between 0 and unlimited times", so to match the * literal, we have to escape it: \*, and to make it optional, we use the ? quantifier (it means "the thing before me between 0 and 1 times").Whitespaces (the amount depends if a * was there or not).To solve this problem, we can use a better regular expression than just main. Will return successfully if any branch containing the word main exists. So to check if we are in a git repository while also hiding possible error messages, I did this:Įnter fullscreen mode Exit fullscreen mode I'm not really interested in the error message, just the exit code (zero or non zero). When we are not in a git repo, it prints an error message and exits "non zero", according to the manual. man git rev-parse shows more details, and the -git-dir option indeed looks like a good option. We have to think about something else, but hopefully git itself already has some quick way to check this.Ī quick google search showed me that the command git rev-parse -git-dir can be used for this task. This is not a very good solution because it will not work if we are inside a subdirectory of a git repository. Print some error message and exit non zero code otherwiseĪ simple, and not very good, way would be to just execute ls. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |