this post was submitted on 05 Aug 2023
15 points (85.7% liked)

Programming

16975 readers
1288 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 1 year ago
MODERATORS
 

Let's say a repo named cool-stuff is on github.
I have a fork of cool-stuff and I have submitted a PR associated with my fork of cool-stuff which is waiting to be merged.

Now, there is another independent fork of cool-stuff,say, even-cooler-stuff which works on new features to introduce to cool-stuff. I would like to contribute to the even-cooler-stuff repo but github won't let me since I already have a fork of cool-stuff.

Is there any way to do what I want like this or should I manually tell the author of even-cooler-stuff the changes I want to do?

all 11 comments
sorted by: hot top controversial new old
[–] [email protected] 37 points 1 year ago* (last edited 1 year ago) (2 children)

You can add the even-cooler-stuff as another remote repo(like origin) and grab those changes and branch off of one of is branches then you can make pull requests to even cooler stuff from those branches.

https://stackoverflow.com/questions/7244321/how-do-i-update-or-sync-a-forked-repository-on-github

I'm pretty confident the reason GitHub isn't allowing you to fork the even-cooler-stuff repo is that technically they are the same repo... And multiple remotes should do the trick.

[–] [email protected] 19 points 1 year ago* (last edited 1 year ago) (1 children)

I blame GitHub for this. They invented this cool concept of a "fork" which is not technically a fork but only a stupid clone with another remote URL, and "pull request" which is basically a merge request with another name. It's confusing and seem to create problems across teams /rant

[–] [email protected] 10 points 1 year ago* (last edited 1 year ago) (2 children)

The name "pull request" is actually more accurate, because you ask the upstream repository to git pull the changes from the downstream repo.

[–] [email protected] 6 points 1 year ago

Either one works imo, as the maintainer is asked to merge your changes into his repo.

[–] [email protected] 2 points 1 year ago (1 children)

It's only more accurate because they actually put the fork in a "different" repo (which really is the same repo).

If you only have one repo like in Gitlab, merge request is more accurate.

[–] [email protected] 2 points 1 year ago* (last edited 1 year ago)

Whenever possible, it’s recommended to work in a common Git repository and use branching strategies to manage your work. However, if you do not have write access for the repository you want to contribute to, you can create a fork.

A fork is a personal copy of the repository and all its branches, which you create in a namespace of your choice. Make changes in your own fork and submit them through a merge request to the repository you don’t have access to.

https://docs.gitlab.com/ee/user/project/repository/forking_workflow.html

How is this different from GitHub?

Just to make sure there's no misunderstanding: When I want to contribute to a project I'm not involved in, like inkscape, I'm not allowed to create a branch in their repo, so I have to fork it, which creates a copy of the repo, and sets the original repo as a remote.

Note that git is a distributed VCS that doesn't distinguish between servers and clients. Forking and cloning are the same operation from a technical perspective, except when you git clone, the copy ends up on your local machine, and when you press the "fork" button, the copy is on a GitHub/GitLab server.

[–] [email protected] 1 points 1 year ago (2 children)

So, if I understand correctly,you mean :

  1. make a new repo and add even-cooler-stuff as remote.
  2. fetch changes from the remote even-cooler-stuff.
  3. make your changes and push to your repo

now I should be able to make a pull request?

[–] [email protected] 4 points 1 year ago* (last edited 1 year ago)
  1. Use your existing fork of 'cooler-stufff'

Everything else is the same.

Edit: you should actually be able to make a new repo and just file your three steps... Give it a try.

[–] [email protected] 3 points 1 year ago

Apparently, someone else posted the same solution that I did while I typed it out. Sorry for the duplicate but at least weagree on the solution! A warning on this one though. You want to use a feature branch too. Otherwise you'll mix your changes for cool-stuff with new changes for and from even-cooler-stuff. It may become more confusing and difficult to merge.

[–] [email protected] 9 points 1 year ago

Create a new branch on your fork. You need it to be synced with the other fork so there are a few extra tricky steps. On your new branch, you need to delete the latest commits that aren't merged yet so that it matches the original repo. Then add a remote for the other fork and pull. Now you can build against the other fork and submit a PR to it.

git checkout -b even-cooler-stuff
# Remove the last 8 commits. Change this number as needed. Increasing it "too high" is just fine 
git reset HEAD~8 --hard
git remote add even-cooler-stuff https://github.com/more-of-url/even-cooler-stuff
git pull even-cooler-stuff

You should now have a branch that matches the other fork. Make your changes, commit, and push normally. When you build the PR, you want to merge into the other fork.

Disclaimer: I wrote this on my phone and from memory. There are probably typos and possibly other mistakes. Good luck!