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?
3 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

- 15,810
- 15
- 45
- 67
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 git@github.brucewangno1/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"

- 5,515
- 21
- 33
This answer assumes that you forked repository https://github.com/rylio/ytdl/ to https://github.com/brucewangno1/ytdl
You need to create directory named rylio
in your $GOPATH
and clone your fork into that directory.
mkdir $GOPATH/src/github.com/rylio
cd $GOPATH/src/github.com/rylio
git clone https://github.com/brucewangno1/ytdl
Now, you will not face any issues related to the imports.

- 175
- 4