Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to do if I want to make changes to a forked repository only to find that I can not because the forked package import itself

Tags:

github

go

Like this github repository, I forked the repository and made some changes to the code. When I run it, my changes are not in effect because the original code imports itself. I could simply just change the import library to mine like "import github.com/brucewangno1/ytdl". But is there any other clean way to avoid this?

like image 276
Bruce Avatar asked Dec 16 '25 12:12

Bruce


2 Answers

Another easy way is to use go get instead:

$ go get github.com/original/a_library
$ cd $GOPATH/src/github.com/original/a_library
$ git remote add my_origin https://github.com/myaccount/a_library

In your case it will be

$ go get github.com/rylio/ytdl
$ cd $GOPATH/src/github.com/rylio/ytdl
$ git remote add my_origin https://github.com/brucewangno1/ytdl

Once you are done with changes, commit them and push using below:

$ git push my_origin my_branch
like image 150
Aditya Singh Avatar answered Dec 19 '25 05:12

Aditya Singh


When working with golang forks of a repo, try and work in the import path of the original repo, and update the tooling to use your forked repo.

What I mean is, if you have forked the project github.com/rylio/ytdl/ to your own github account github.com/brucewangno1/ytdl

Then you might have a gopath such as:

$GOPATH/src/github.com
├── rylio
│   └── ytdl
└── brucewangno1
    └── ytdl

You should make changes in the directory $GOPATH/src/github.com/rylio/ytdl.

To add the changes to your forked repo, you can set another origin in git, inside your local clone of rylio/ytdl

git remote add fork [email protected]/tydl.git

If you do not plan on merging changes back into the upstream repo, you can use tools such as dep to ensure that you pull your own fork of that project instead of the upstream one. Something like:

[[constraint]]
name = "github.com/c/d
source = "https://github.com/myusername/d.git"
like image 23
Zak Avatar answered Dec 19 '25 05:12

Zak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!