MCPcopy Create free account
hub / github.com/cli/cli / AddRemote

Method AddRemote

git/client.go:843–874  ·  view source on GitHub ↗
(ctx context.Context, name, urlStr string, trackingBranches []string)

Source from the content-addressed store, hash-verified

841}
842
843func (c *Client) AddRemote(ctx context.Context, name, urlStr string, trackingBranches []string) (*Remote, error) {
844 args := []string{"remote", "add"}
845 for _, branch := range trackingBranches {
846 args = append(args, "-t", branch)
847 }
848 args = append(args, name, urlStr)
849 cmd, err := c.Command(ctx, args...)
850 if err != nil {
851 return nil, err
852 }
853 if _, err := cmd.Output(); err != nil {
854 return nil, err
855 }
856 var urlParsed *url.URL
857 if strings.HasPrefix(urlStr, "https") {
858 urlParsed, err = url.Parse(urlStr)
859 if err != nil {
860 return nil, err
861 }
862 } else {
863 urlParsed, err = ParseURL(urlStr)
864 if err != nil {
865 return nil, err
866 }
867 }
868 remote := &Remote{
869 Name: name,
870 FetchURL: urlParsed,
871 PushURL: urlParsed,
872 }
873 return remote, nil
874}
875
876// Below are commands that make network calls and need authentication credentials supplied from gh.
877

Callers 5

cloneRunFunction · 0.80
forkRunFunction · 0.80
handlePushFunction · 0.80

Calls 3

CommandMethod · 0.95
ParseURLFunction · 0.70
OutputMethod · 0.65