7/2/2023 0 Comments Git list branches![]() Now I’ll create a new file and stage it for committing, but I won’t commit it (this is where we pretend my branch is in some hideously complex state). Note: I use tmux to split my terminal into multiple windows, and this demonstration will require two windows (or two separate terminal instances if you’re not using a screen multiplexer) for the sake of demonstration. We’ll then imagine that I have been given an urgent task that I must complete now and yet my current non-master branch is in such a state that I want to avoid just stashing everything. I’ll make a change in master, then create a new branch for doing some work. In the following example I’m going to create a new git repo. I’ll leave that up to the reader to decide. Note: as you’ll see, although this workflow is pretty cool, you could argue that git stash is just plain simpler and easier for a human mind to reason about. ![]() This is different to manually creating a new directory and git cloning your repo down, because with the worktree model the two sub directories are aware of each other. It does this by creating a new directory for you with a copy of your git repository that is synced between the two directories where they are stored. Git offers a feature referred to as a worktree, and what it does is allow you to have multiple branches running at the same time. This is where I was recently introduced to a concept in git referred to as a ‘worktree’ (thanks Kiran). Oh, and then you have to think about whether you actually want to use apply, which leaves the stashed changes in the stack, or if you meant to actually pop the stashed content ( git stash pop so it’s properly removed from the stack. Note: for the life of me I wish I could remember the syntax but it just eludes me every time. ![]() it’s git stash apply where n is the index you want to apply.) OK so not that tragic considering git stash list will indicate the branch on which the stash was taken (which helps), but I do then need to Google what the syntax is for popping a specific stash (e.g. Ultimately, when I’m done with my urgent task and ready to go back to my other branch, I then have to sift through my stash to find the relevant one I want to pop. This is a fairly straightforward workflow, but there is a mild annoyance which is that I happen to git stash a lot and I find when jumping over to a new branch to do some urgent work that I might end up git stash‘ing a few more times along the way. Typically you would need to first git stash anything you were working on (as it’s unlikely to be in a state where it can be committed), and then you’d have to leave your current branch to create a new branch from master and thus begin working on your new urgent task. When executing echo *, your shell first expands and replaces * with all (non-hidden) files in your current directory, then passes this list of files as parameters to echo.There are times where you might be working from a particular git branch and need to quickly jump over to a different branch to do some urgent work. And as you might know, * as a globbing character/wildcard, which resolves to any 0 or more characters. Since git branch is a user-facing command, it marks the current branch with a *. Not quoting a parameter expansion (or command substitution) will perform pathname expansion on the expanded value. This avoids the problem of the command from the question, because it correctly quotes parameter expansions. Or git for-each-ref -shell -format='%(refname:short)' refs/heads | \ While read branch do git branch -d "$branch" done Instead, use the low-level commands such as git for-each-ref: git for-each-ref -shell -format='%(refname:short)' refs/heads | \ But why does $(git branch) outputs all these file names besides the git branches?ĭon't use git branch in scripts. If I echo $(git branch), the output is like this: $ echo $(git branch)Īngular.json assembly.xml ci-settings.xml coverage cypress.json Dockerfile.angular Dockerfile.spring e2e examples mvnw mvnw.cmd nginx node node_modules package.json package-lock.json pom.xml README.md scripts src target to-do.txt tsconfig.json web.config dev It does what I want, but also tries to delete branches named as files in current directory, so the output is something like this: error: branch 'angular.json' not found.Įrror: branch 'ci-settings.xml' not found.Įrror: branch 'Dockerfile.angular' not found.Įrror: branch 'Dockerfile.spring' not found.Įrror: branch 'package-lock.json' not found.Įrror: branch '' not found.Įrror: Cannot delete branch 'dev' checked out at 'D:/Documentos/oreons/Rise/archivekeeper-ui' ![]() ![]() I wrote a command to delete all git branches without needing to write them all mannually, which is currently like this: git branch -d $(git branch) ![]()
0 Comments
Leave a Reply. |