GitHub CLI 1.0
github.blog
github.blog
Basically I want to be able to pull up a buffer with a list of issues assigned to me and copy them into my org mode todo list
The only package I've been ultimately responsible for is the Gruvbox theme[^1], but that was very quickly handed over to other emacsers :)
I still find it a joy to write and it's one of my more preferred rabbit holes to dive into. Maybe one day there'll be something more to share :)
Goddamn merge commits, and always have to go googling "oh shit how do I erase the last commit" when I accidentally commit to master. It should at least spit out a warning if you created a branch and then try to commit to master. Git lfs and git-crypt should be a feature of the main product and not plugins. Files over a certain size should be transparently LFSed without some need to "track" them or install a plugin to fetch them. It's too hard to accidentally forget to encrypt something or LFS something. Gitignore is easy to screw up and accidentally commit a sensitive credentials file. And "git rm" also removes the file locally with no recourse -- that should not be the default behavior.
Also, the whole UX around submodules REALLY sucks ... is it git submodule update --recursive --init? git submodule init --update --recursive? git init submodule --recursive? I can't remember for the life of me. Why can't it auto-clone all submodules when you clone the parent repo, seeing as you kind of need them to do anything? The UX is so bad that I often just copy the contents of the repo instead of using submodules.
This seems to be a good resource https://githooks.com/
How this one may be done? It sounds wonderful but I have no idea how to implement such thing (and if not included in git already, I hope that I can reuse code rather than reimplement it)
and I would want
"spit out a warning if you created a branch and then try to commit to master"
Sometimes I would want to commit to master, I want an overridable warning iff I just created branch.
#!/bin/sh
BRANCHES_POINTING_TO_HEAD=$(git branch --contains HEAD |wc -l)
CURRENT_BRANCH=$(git branch --show-current)
if [ "$BRANCHES_POINTING_TO_HEAD" -gt 1 ]; then
if [ "$CURRENT_BRANCH" = "master" ]; then
echo "You're committing to master even though other branches exist."
echo "override with git commit --no-verify"
exit 1
fi
fi
You'll need git 2.22 for the --show-current git option.But also I would suggest instead using
git checkout -b <new_branch>
to create and switch branches in one command $ git checkout <new_branch>
<new_brach> doesn't exist. Would you like to create it (Y/n):
The real problem with "git" is just way too many options. For automated tools there can be a "-n" non-interactive option that fails with an error code and doesn't ask questions.He recommended using YAML for all Pipeline Development as they were trying very hard to ensure that it would be compatible but legacy pipelines would not.
Other common CLIs written with the same framework: kubectl, hugo, rclone (to name a few)
Really is a great option.
Github for me is simply a repo of open source code that I can inspect before I use someone else library.
FWIW gh is built by some of the same people that built & maintain hub.
It's the only way to stay sane in a repo with multiple other developers merging PRs. Updates all of your branches in the background to the current remote version.
gh on the other hand seems to very specifically work on GitHub’s non-git features, like Issues, PRs, repositories.
https://github.com/stephencelis/ghi
It's pretty nice. I like seeing these features supported officially (I think hub supported many of these unofficially for years).
What tools are there like this for Gitlab? I remember struggling just to find a decent CLI for their issue tracker.
All my new stuff is on Gitlab and I prefer Gitlab since if I ever want to, I can always just management my own instance and migrate to it. No such options with Github.
That said, I use both. Most of my commits etc. are on the CLI but I still switch to a GUI if I want to browse the repo or see more detailed diffs etc.
I usually need to double check open issues when making these messages and since I am already writing commits on the command line, having a split terminal or tab that can pull up active commits with a single line command and see them in a concise and clean format, it is super helpful and fast.
If you are already working in the command line all day long, then it makes perfect sense to have access to GitHub in the command line as well.
Another benefit is that most IDEs will have direct terminal access within the IDE, which means you can get relevant GitHub details about your project from within the IDE via the terminal, without needing to leave the IDE.
Lastly, the CLI version is far more concise and simple compared to the web version.
I am not hating the web version. I still use the web version plenty. But it is just another useful tool in the quiver that has plenty of use cases and simplifies workflow.
`gh pr create --web`
Saves me having to push my current branch, navigate to the repo page, hit the "create PR" button, etc.
I've been doing `git push -u origin HEAD` and then using my mouse to click on the "go here to create a PR" link that gets printed, which isn't too bad. Takes you right to the page where you can review the changeset before opening the PR. If I'm not actually ready to open a PR by the time I push upstream, I just open a draft instead.
My favorite is "git browse", which opens a browser for the current repo & branch. There are a few other commands that are probably useful but that I don't really do much with.
gh alias set pcw 'pr create --web'
and then just use gh pcw
to create a new PR. There's also sufficient smarts around forking or not, depending on write permissions on the upstream repo. gh pcw --base=development
It's also super quick to set up an alias, so I don't see why not.This type of alias seems on the fence for me, if was like 10x a day I'd definitely be on board but a few times a day is a gray area
One example that comes to mind - we used hub to hack together a quick security feature that errors out our CI/CD pipeline (which runs shell scripts) if there are any open PRs that are labeled "security" (i.e. Dependabot opening a PR to update a vulnerable library), which forces developers to keep their dependencies up-to-date in order to deploy into production.
GUI tools don't work as part of CI/CD pipelines.
Libraries in higher-level languages (e.g. Python) force you to make sure that there's a library for every tool that you work with - if a specific tool is missing a Python library, then you have to deal with that yourself. Shell scripting is much more productive for gluing multiple sets of tooling together, as long as the shell scripts remain of a maintainable length.
With this tool, I was able to do something similar using Github as the source of information instead[1].
I fetch the info using the gh tool, output the result into json, and use a python script to format the output which results in a decent looking automatically generated changelog[2].
It's not the most exciting thing, and I could have probably achieved it in a different way using the GraphQL API directly, but for the needs of the project this fit the bill and let me get on with the release.
[1] https://github.com/aurora-scheduler/aurora/blob/master/build...
[2] https://github.com/aurora-scheduler/aurora/blob/master/CHANG...
However, you can approximate visual representations of these things in a CLI - `git log --graph --pretty=oneline --decorate --abbrev-commit` will use ASCII characters to draw the DAG of commits.
Moreover, the GitHub web GUI is not "amazing". It's tolerable as far as web UIs go, but it's missing a lot of keyboard shortcuts (and none of them are customizable), has no built-in extensibility (the fact that you can inject your own scripts and stylesheets is a hack only at the display level, and an impractical one at that), EDIT: isn't scriptable, and is incredibly resource-intensive relative to a native application. The GitHub CLI allows you to manage the non-git parts of GitHub from the command-line (and make your own GitHub native client by extension) - which is desirable, given the above.
I don't think the GH web interface is even tolerable. Even Bitbucket, which really sucks, has a better one...
For me, being able to just note down in a text file an exact trace of what I've done is the gist of why CLIs are superior for my use. How do you even begin to keep track of what you do in a GUI? You could record video, but the information density is way too low for it to be useful, and it's worthless for automation.
A lot of my stuff gets automated by me first doing stuff manually, recording what I do in a script, and next time just running said script. That's just flat out not possible with most GUI tools, and even if it were, it's too cumbersome to be worth doing.
Often true for me as well. I like `tig`.
> What use case is better served by sticking to the cli?
Good question. Knowing the "why" of things is important. My answers:
1. Focus - Opening a browser and clicking around takes more patience. It tempts me to go update my company's internal documentation about something irrelevant to my current task.
A CLI lets you pipe things to grep which lets you focus on specific information you care about.
2. Memory - I can write aliases to help me remember my common workflows.
3. Automation - I can have a script check PRs for me. This reduces context switching and enables greater focus and productivity.
2. Is often unimportant if the GUI tool can make common workflows one or two clicks.
3. Having the CLI tools to automate stuff is great, but is not necessarily the best way to have an interactive session with a repository.
Some of the things I like about graphical interfaces for Git:
- The information density is usually (depending on the program) great - I can see local branches, remote branches, commits and tree diagram for the selected branch, all in less space than a terminal usually takes up.
- A bunch of actions are available by right-clicking on a relevant item, so I don’t have to remember commands and command-line flags etc and I can just get on with things.
- Some actions like “show me the diff between these two commits” are SO much easier that they become a viable way of working.
today I wanted to see the commit history and changes of a single file. I tried for 20 minutes to figure how to do that in sublime merge some of that searching online. Failed. Used the command line like I probably should have in the first place.
1. Selecting specific lines for a commit. 2. Stashes management 3. Rebasing branches, cherry picking commits.
It is possible to do a lot more with it, but for the most other operations I use command line or GitHub UI.
My favorite feature is ctrl+click 2 nodes in the git tree and immediately see file level diff which I can explore in vscode’s diff viewer.
For work, we use git flow with github PR (which I do on github website) and always work in feature branches. I am able to navigate git like a pro, cherry picking etc as needed without a problem. It even works well with git submodules.
If something goes unexpected, git graph is the best tool to figure out what happened and to be able to repair it.
Also, vscode handles merge conflicts in a way I can actually understand and correct without it slowing me down.
The GIT cli has the option to use an external diff helper if you prefer.
You know how a lot of people think merge commits (an important keystone in how easy Git makes it to read and write meaningful history) are inherently "confusing" or "messy", and try to avoid creating them? Well, if you look at them in Github's awful log interface, they sort of are! This doesn't seem like the fault of those developers, and it's not Git's fault, since it ships with powerful command-line and GUI tools for making sense of things.
There can be UI and sometime that's helpful, but all action contained therein will be available on cli, just because that's exactly what the UI calls.
But by the way, `hub browse` and `hub sync` are handy too.
I never did use `hub` as a "wrapper" for `git`, I've always typed `hub pull-request`. I never liked the wrapper idea. So I approve of `gh` abandoning it.
Or maybe git-appraise https://github.com/google/git-appraise git-bug https://github.com/MichaelMure/git-bug
And recently discussed here https://radicle.xyz/
https://github.com/google/git-appraise
https://github.com/dspinellis/git-issue
Would be nice to have something more polished though.
It never seemed like the distributed "selling point" of Git (and Mercurial et al) really caught on. I remember trying to extoll it's virtues to our team at the time (pre-Github). No one source of truth as such, just everyone swapping changes as needed. It's kind of ironic that Git's most popular incarnation is based upon a centralised model.
Is it just a case of the distributed workflow just not being that useful for most people? Beyond the obvious example of Linux kernel development, of course!
Are people forgetting what life was like back in SVN days, when not having a connection to the server meant not being able to do many operations?
They have a document where they expand on this: https://github.com/cli/cli/blob/trunk/docs/gh-vs-hub.md
"The GitHub CLI team is focused solely on building out the new tool, gh. We aren’t shutting down hub or doing anything to change it. It’s an open source project and will continue to exist as long as it’s maintained and keeps receiving contributions."
"hub is a project whose maintainer also happens to be a GitHub employee. He chooses to maintain hub in his spare time, as many of our employees do with open source projects."
My experience at FANMAG has been that "spare time" is the scarcest of all resources.
There is no particular plan to phase out hub, but once github CLI covers enough features, I'd expect people to switch over to it.
It seems kinda like making a cli tool for a web interface for a tool. I guess I'm just missing something.
Edit: Spelling.
So a wrapper for an API for a website for git? Why?
Edit: Also, how does anything working with GitHub have nothing to do with git?
Edit 2: Don't get me wrong, this looks like a cool tool. I'm just curious about the motivation.
[0] https://en.wikipedia.org/wiki/Embrace,_extend,_and_extinguis...
If you are referring to GH being owned by MS now, it's 2020 for godsake. Can we move on from our fathers' trauma? MS has been damn good lately in support of developers and developer tools.
I personally remain very uncomfortable with how massive GitHub has become and how ~99% of software development happens on the platform.
Furthermore, technology isn't the lock-in - it's the network, which you can't drag as easily.
https://github.com/lionsharecapital/lionshare-desktop/tree/m...
I'm a n00b though, might just be because I'm dumb. But when they have actually dumbed down the CLI and spent time and resources to make it so user-friendly, shouldn't they have went thorough with it to make it as intuitive as Github Desktop?
Working with BB APIs has not been fun at any point in the past 5 years or so :(
Tip - there is a "deleted repos" section in GitHub UI where they will appear, apparently with an option to restore them.
In short - all I said seems to have been nonsense. Apologies!
Still, the main issue was the process how they handled it. Your build breaks. This is how we found out.
No recourse for such decisions unless you make a stink about it on an orange website or get enough likes on the website with the blue bird logo.
Furthermore, no: GitHub has a history of being bad at this kind of thing:
https://news.ycombinator.com/item?id=22593595
From the linked article: "A week after I’ve opened the support ticket, GitHub has finally replied. Suspiciously, this happened right after someone important has posted a link to this article on Hacker News"
https://news.ycombinator.com/item?id=22628961
Top comment: GitHub CEO coming in and apologising. From the linked tweet: "You sited US trade sanctions and sent me a non-descriptive email with no remediation information".
Clearly not that irrelevant if you're in here commenting.
It's an excellent tool even if you just use it to quickly create and view PRs and issues, as I do.
Extend - in progress
Extinguish - todo
I also wonder what this is going to do for folks not using Github as now CLI users are going to "unlearn" all their traditional git commands.
There are 3 main commands from the CLI you can issue:
gh
CORE COMMANDS
issue: Create and view issues
pr: Create, view, and checkout pull requests
repo: Create, clone, fork, and view repositories
I still use the git cli and the github UI, but sometimes just view open PR's from the my terminal if I'm already in there.Some commands seem to be purely github related, which make sense, some others seem to overlap with just plain git.
> Clone the repository you want to work with using gh repo clone owner/repo
Like, what does this do apart from a regular git clone? Why is this necessary? I guess it additionally stores some meta information so that other "gh" commands know which repo they are on. This should have been a separate command IMHO to leave the regular git clone alone. Something like "git clone ssh://github.com/foo/bar" followed by "gh init foo/bar".
> When you’ve finished adding that feature or fixing that bug, use gh pr create
Same goes here. Why overlaying git commands? I would have expected to just push my branch, and then call something like "gh pr create <my branch> <target branch>"
> And your teammate can check out your pull request using gh pr checkout 1337
Same remark again and again, what does that do apart from checking out a branch? Why the overlay?
> view the diff with gh pr diff
So what's wrong with "git diff <target>..<source>"
> gh pr merge
Come on.. "git co <target> ; git merge <source>" needs to be overplayed?
> gh release create [tag name]
Oh sure, let's overlay git flow as well.
I mean overall the tool looks cute and all, but magic overlays is a no no for me.
> Like, what does this do apart from a regular git clone? Why is this necessary?
You can't see a difference between ```gh repo clone owner/repo``` and ```git clone git@github.com:owner/repo.git```?
Also:
> Something like "git clone ssh://github.com/foo/bar" followed by "gh init foo/bar"
What's there to "init"?
> Same goes here. Why overlaying git commands? I would have expected to just push my branch, and then call something like "gh pr create <my branch> <target branch>"
From the docs: "When the current branch isn’t fully pushed to a git remote, a prompt will ask where to push the branch [...]"
> Same remark again and again, what does that do apart from checking out a branch? Why the overlay?
It resolves the pr # to the corresponding branch name, probably git fetch and checkout. Why should I have to know the irrelevant piece of information that is how you named your branch?
> So what's wrong with "git diff <target>..<source>"
How do you find out the target and source hashes? Another piece of convenience.
> Come on.. "git co <target> ; git merge <source>" needs to be overplayed?
And this is wrong. This merges source in target locally, ```gh pr merge``` merges it remotely. You can be Linus Torvalds, you are not going to push to my master branch.
Makes switching to other vendors more painful further down the line.
This utility does.
If you are uncomfortable with using GH to manage issues and PRs you shouldn't probably shouldn't be using GH.
It's open source [0], there's nothing stopping you hooking it up to Gitlab, or pointing it at jira.