Home > Blockchain >  How can I get the URL to a merge request or a pull request of my current branch using git?
How can I get the URL to a merge request or a pull request of my current branch using git?

Time:09-02

I would like to obtain the link to the associated PR/MR of the current branch using Git CLI.

CodePudding user response:

You mean https link ?

I don't know the way to get the link you want,

but you can get that kind of link by webhook of GitLab after the PR/MR event.

webhook: https://docs.gitlab.com/ee/user/project/integrations/webhooks.html#webhooks

CodePudding user response:

Git is unaware of pull (GitHub) or merge (GitLab) requests. This means that the Git CLI is unable to do what you want.

Git is, however, a set of tools, not a specific solution. You can simply add your own tools. The Unix-style of working is to treat everything as a tool, to whatever extent possible, so if you're using bash or zsh, you can add non-Git tools as well.

GitHub, for instance, provide a CLI tool of their own called gh. There is a StackOverflow tag for gh-related questions: . There are also GitLab tools, e.g., this one and this one, although there don't seem to be StackOverflow tags for these.

You'll find one big stumbling block here, and that is the fact that branches, in Git—regardless of which of several common meanings you intend by the word branch—are slippery and have little real substance. There may be a branch named feature/tall in repository X on GitHub, which you use in your own clone under the entirely different name feature/short. Is this branch "tall" or "short"? The answer is either "yes" or "both".

The simple solution to this stumbling block is "don't do that": if you keep your names such that they match up with some other repository's names, you won't ever hit this problem. The fault with this simple solution occurs when there are multiple "other repositories" in question and they:

  • use different names, and/or
  • use the same names, but for different commits

which results in you being unable to use a single name to match. But this is rare, so you may be able to ignore it.

  • Related