{"id":13232,"library":"git-up","title":"Git URL Parser","description":"git-up is a dedicated, low-level JavaScript utility designed for robust parsing of various Git URL formats, including SSH (e.g., `git@github.com:user/repo.git`) and HTTPS (`https://github.com/user/repo.git`). It meticulously breaks down a given URL into a structured object, exposing components like protocols, port, resource, user, pathname, hash, search, href, and the derived Git protocol. The current stable version is 8.1.1, with recent releases indicating active maintenance and the addition of TypeScript types in version 8.1.0. Its release cadence is somewhat irregular, often driven by updates to its core dependency, `parse-url`. A key differentiator is its specific focus on Git URL nuances, making it more reliable for Git-centric tooling compared to general-purpose URL parsers, which might not correctly interpret SSH syntax or project paths.","status":"active","version":"8.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/IonicaBizau/git-up","tags":["javascript","git","url","parser","parsing","typescript"],"install":[{"cmd":"npm install git-up","lang":"bash","label":"npm"},{"cmd":"yarn add git-up","lang":"bash","label":"yarn"},{"cmd":"pnpm add git-up","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core dependency for URL parsing logic, frequently updated with major versions impacting git-up.","package":"parse-url","optional":false}],"imports":[{"note":"For ESM, `gitUp` is the default export. For CommonJS, it is the module's direct export, typically accessed as `const gitUp = require('git-up');`.","wrong":"import { gitUp } from 'git-up';","symbol":"gitUp","correct":"import gitUp from 'git-up';"},{"note":"TypeScript users can import the `GitUpResult` interface for type safety when working with the parsed URL object, available since v8.1.0.","symbol":"GitUpResult","correct":"import type { GitUpResult } from 'git-up';"},{"note":"Wildcard import can be used to access the module object, though direct import of `gitUp` is more common.","wrong":"const GitUp = require('git-up');","symbol":"* as GitUp","correct":"import * as GitUp from 'git-up';"}],"quickstart":{"code":"import gitUp from 'git-up';\n\nconsole.log(gitUp('git@github.com:IonicaBizau/node-parse-url.git'));\n// Example Output:\n// {\n//     protocols: []\n//   , port: null\n//   , resource: 'github.com'\n//   , user: 'git'\n//   , pathname: '/IonicaBizau/node-parse-url.git'\n//   , hash: ''\n//   , search: ''\n//   , href: 'git@github.com:IonicaBizau/node-parse-url.git'\n//   , protocol: 'ssh'\n// }\n\nconsole.log(gitUp('https://github.com/IonicaBizau/node-parse-url.git'));\n// Example Output:\n// {\n//     protocols: [ 'https' ]\n//   , port: null\n//   , resource: 'github.com'\n//   , user: ''\n//   , pathname: '/IonicaBizau/node-parse-url.git'\n//   , hash: ''\n//   , search: ''\n//   , href: 'https://github.com/IonicaBizau/node-parse-url.git'\n//   , protocol: 'https'\n// }","lang":"typescript","description":"Demonstrates parsing both SSH and HTTPS Git URLs and logging the structured output, showcasing the detailed breakdown of URL components."},"warnings":[{"fix":"Thoroughly test existing parsing logic and adapt code if `parse-url` 9.x.x introduces changes to the parsed object structure or edge case handling.","message":"Major dependency `parse-url` was upgraded to 9.x.x, which includes breaking changes. Review `parse-url` release notes for potential changes in URL parsing behavior and the structure of the output object.","severity":"breaking","affected_versions":">=8.0.0"},{"fix":"Review `parse-url` 8.x.x documentation and update any code that relies on specific parsed URL properties or behaviors that may have been altered.","message":"Upgraded `parse-url` to 8.1.0, which was explicitly noted as a breaking change. Consult `parse-url`'s release notes for details on how URL parsing and output might have changed.","severity":"breaking","affected_versions":">=7.0.0 <8.0.0"},{"fix":"Update logic handling `pathname` to account for trailing slashes, ensure `port` is treated as a string, and adjust any code that expects specific `resource` formats or relies on the absence of a `password` field.","message":"Introduced several breaking changes: trailing slashes in input URLs are now preserved in `pathname`, the `port` field is always a string (empty by default), a new `password` field is added (default `\"\"`), and the `resource` field may now include the port (e.g., 'domain.com:4200').","severity":"breaking","affected_versions":">=6.0.0 <7.0.0"},{"fix":"For Safari compatibility, ensure `normalize-url` is updated or consider upgrading to `git-up@6.0.0` or later, as subsequent `parse-url` updates may have resolved the underlying issue. Always test thoroughly in Safari.","message":"Due to compatibility issues with `normalize-url` (a transitive dependency of `parse-url@6.0.0`), `git-up` versions released around this period may exhibit broken or unexpected behavior in Safari browsers without a specific patch to `normalize-url`.","severity":"gotcha","affected_versions":">=4.0.5 <6.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change the import statement to `import gitUp from 'git-up';` to correctly import the default export.","cause":"Incorrect ESM import syntax; attempting to destructure a default export or using a named import when the module provides a default export.","error":"TypeError: (0 , git_up__WEBPACK_IMPORTED_MODULE_0__.default) is not a function"},{"fix":"Update `git-up` to the latest version and ensure your `node_modules/@types/git-up` are regenerated. Review the `GitUpResult` interface in the latest version for current property names and types, especially after major version bumps (e.g., `port` changed to `string` in v6).","cause":"Accessing a property on the parsed object that may have been renamed, removed, or changed its type in a new major version, or using an outdated TypeScript type definition.","error":"Property 'protocol' does not exist on type 'GitUpResult'."},{"fix":"Ensure the `input` argument passed to `gitUp()` is always a string representing the Git URL to be parsed.","cause":"Calling `gitUp()` with an argument that is not a string, or passing an unsupported input type.","error":"Error: The \"input\" argument must be of type string. Received type object"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}