Tuesday, February 11, 2020
Tuesday, August 21, 2018
git bash - deleted local branches
You can find out which branches have been merged into a branch by running the below:
This will also print out master as part of it, so we can then pipe that into grep to match results without master:
Obviously, you won't want the name master in your branch name, otherwise it'll be excluded too. You can fancier with regex here.
Now we can take this result and pipe it into xargs, to run git branch -d passing the output as arguments
I'm splitting up the command onto separate lines for readability. The -r will only run the git command if there is output.
I've noticed this doesn't always delete all old branches, but it can help. For example, perhaps you had a branch that was a work in progress, or a spike, with changes that aren't merged - this won't be picked up.
You can do one more trick to detect old branches that have no upstream branch anymore:
$ git branch -vv
This will list branches without an upstream branch with gone. Those can generally be deleted too.
$ git branch --merged origin/master
* master
feature/some-branch
feature/some-other-branch
$ git branch --merged origin/master | grep -v master
feature/some-branch
feature/some-other-branch
Now we can take this result and pipe it into xargs, to run git branch -d passing the output as arguments
$ git branch --merged origin/master
| grep -v master
| xargs -r git branch -d
I've noticed this doesn't always delete all old branches, but it can help. For example, perhaps you had a branch that was a work in progress, or a spike, with changes that aren't merged - this won't be picked up.
You can do one more trick to detect old branches that have no upstream branch anymore:
$ git branch -vv
This will list branches without an upstream branch with gone. Those can generally be deleted too.
Labels:
bash,
branches,
deleting local branches,
git,
tips
Monday, August 20, 2018
Today I learned - VSTS CLI and jq
Today I learned about the VSTS command line tool from a colleague.
I might actually have heard about it before, but wasn't able to try it out because I was previously using the on-premise TFS and not the cloud based VSTS, but hey, today I tried it out :)
For example, you can query VSTS for pull requests you've created by doing the following:
$ cd /your-vsts-git-repo
$ vsts login
$ vsts code pr list --creator "James Barrow"
This will return a JSON object containing info about what pull requests you have created.
If you don't really care about the entire structure, you can then use another command line tool I've come across before called jq.
For example, if you only care about the title, status and url of the pull request, you could do the following:
$ vsts code pr list --creator "James Barrow" | jq ".[] | { title, status, url }"
That's a long command, but what it basically does is pipes the JSON result into jq, which parses it by taking each element in the array of the result, and then filtering it to only take the title, status and url properties of each item in the array.
And finally, since we all know the best way to use git is via the command line and git bash, you can then also create a bash alias in your ~/.bashrc file:
alias prs='vsts code pr list --creator "James Barrow" | jq ".[] | {title,status,url}"'
So you can just check for your pull requests now by simply running:
$ prs
{
"title": "RE #1234 - some pull request",
"status": "active",
"url": "https://blah.visualstudio.com/.../pullRequests/2345"
}
Which gives you something like that ;)
Much simpler than having to open up Chrome, go to VSTS, find the right tab for pull requests, etc...
I might actually have heard about it before, but wasn't able to try it out because I was previously using the on-premise TFS and not the cloud based VSTS, but hey, today I tried it out :)
For example, you can query VSTS for pull requests you've created by doing the following:
$ cd /your-vsts-git-repo
$ vsts login
$ vsts code pr list --creator "James Barrow"
This will return a JSON object containing info about what pull requests you have created.
If you don't really care about the entire structure, you can then use another command line tool I've come across before called jq.
For example, if you only care about the title, status and url of the pull request, you could do the following:
$ vsts code pr list --creator "James Barrow" | jq ".[] | { title, status, url }"
That's a long command, but what it basically does is pipes the JSON result into jq, which parses it by taking each element in the array of the result, and then filtering it to only take the title, status and url properties of each item in the array.
And finally, since we all know the best way to use git is via the command line and git bash, you can then also create a bash alias in your ~/.bashrc file:
alias prs='vsts code pr list --creator "James Barrow" | jq ".[] | {title,status,url}"'
So you can just check for your pull requests now by simply running:
$ prs
{
"title": "RE #1234 - some pull request",
"status": "active",
"url": "https://blah.visualstudio.com/.../pullRequests/2345"
}
Which gives you something like that ;)
Much simpler than having to open up Chrome, go to VSTS, find the right tab for pull requests, etc...
I want to dig more into using jq to pull out info on if the pull requests have had votes as well, so I can just run a command from my command line and see if I need to follow up on a PR or not, but this will have to wait for another day :)
One last note is that use of single and double quotes might be important depending on your shell of choice, so keep that in mind too.
Hope this helped someone.
UPDATE: There is also vsts code pr list -o table which prints a nice format
UPDATE: There is also vsts code pr list -o table which prints a nice format
Labels:
bash,
command line,
jq,
TIL,
tips,
Today I Learned,
Visual Studio Online,
Visual Studio Team Services,
vsts
Thursday, June 28, 2018
AngularJS to Angular, JavaScript to TypeScript, Gulp to webpack to Angular CLI
So I jotted down a whole lot of links for when I was learning webpack, and thought maybe someday I'd write a blog post, but that I probably wouldn't really. That day may come, but that day is not now :P Posting this in case others may want to browse through the links that I found useful when trying to convert an application in AngularJS 1.x with Gulp, using ngupgrade with Angular5 and webpack, onto just one build with the Angular CLI.
https://youtu.be/ivQ7HrnBJe8
https://webpack.academy/p/web-fundamentals
https://what-problem-does-it-solve.com/webpack
https://survivejs.com/webpack/foreword/
https://webpack.js.org/configuration/
https://webpack.js.org/api/
https://webpack.js.org/api/loaders/
https://medium.com/@MarkPieszak/using-pug-or-jade-templates-with-the-angular-cli-9e37334db5bc
ng add ng-cli-pug-loader
https://www.npmjs.com/package/pug-html-loader
https://www.npmjs.com/package/exports-loader
https://github.com/webpack-contrib/copy-webpack-plugin
https://github.com/webpack-contrib/mini-css-extract-plugin
DONT USE > https://github.com/webpack-contrib/extract-text-webpack-plugin
https://github.com/s-panferov/awesome-typescript-loader
https://gist.github.com/sokra/1522d586b8e5c0f5072d7565c2bee693
https://gist.github.com/gricard/e8057f7de1029f9036a990af95c62ba8
https://webpack.js.org/plugins/uglifyjs-webpack-plugin/
http://dmachat.github.io/angular-webpack-cookbook/
https://github.com/dmachat/angular-webpack-cookbook/wiki/Angular-Template-Cache
https://github.com/frederikprijck/angularjs-webpack-starter
https://egghead.io/courses/angular-and-webpack-for-modular-applications
https://youtu.be/ivQ7HrnBJe8
https://webpack.academy/p/web-fundamentals
https://what-problem-does-it-solve.com/webpack
https://survivejs.com/webpack/foreword/
https://webpack.js.org/configuration/
https://webpack.js.org/api/
https://webpack.js.org/api/loaders/
https://medium.com/@MarkPieszak/using-pug-or-jade-templates-with-the-angular-cli-9e37334db5bc
ng add ng-cli-pug-loader
https://www.npmjs.com/package/pug-html-loader
https://www.npmjs.com/package/exports-loader
https://github.com/webpack-contrib/copy-webpack-plugin
https://github.com/webpack-contrib/mini-css-extract-plugin
DONT USE > https://github.com/webpack-contrib/extract-text-webpack-plugin
https://github.com/s-panferov/awesome-typescript-loader
https://www.npmjs.com/package/gulp-inject-webpack-plugin
https://www.npmjs.com/package/indexhtml-webpack-plugin
https://github.com/jharris4/html-webpack-include-assets-plugin
https://github.com/altbit/inject-assets-webpack-plugin
v4.0.0-beta.0 Release Noteshttps://www.npmjs.com/package/indexhtml-webpack-plugin
https://github.com/jharris4/html-webpack-include-assets-plugin
https://github.com/altbit/inject-assets-webpack-plugin
https://gist.github.com/sokra/1522d586b8e5c0f5072d7565c2bee693
https://gist.github.com/gricard/e8057f7de1029f9036a990af95c62ba8
https://webpack.js.org/plugins/split-chunks-plugin/
https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
https://www.youtube.com/watch?v=hQBAQh5AFwA
https://webpack.js.org/configuration/optimization/#optimization-minimizerhttps://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
https://www.youtube.com/watch?v=hQBAQh5AFwA
https://webpack.js.org/plugins/uglifyjs-webpack-plugin/
https://github.com/dmachat/angular-webpack-cookbook/wiki/Angular-Template-Cache
https://github.com/frederikprijck/angularjs-webpack-starter
https://egghead.io/courses/angular-and-webpack-for-modular-applications
Wednesday, June 13, 2018
PowerShell Tips
I'll likely update this as I go along
Create a file like you would with touch
echo $null > filename
Create a file like you would with touch
echo $null > filename
Subscribe to:
Posts (Atom)