(git) how do I commit/push to the team repo? (entirely different history error)

63 views Asked by At

I am trying to make a commit/push to work on team project.

Situation

There is a team project repo at team leader's github. So I forked the team project repo(I am invited in original team repo). Then, I cloned the file to my local and added remote branch called 'pjt' connecting it with my forked repo. I also added new branch for the commit/push to forked repo is 'nb'. I added file using 'git add ', committed it on the 'nb' branch, then pushed using command

git push -u pjt nb

Problem

But this causes error

(forked repo owner name):main and (my ID):nb are entirely different commit histories. 

enter image description here

After this happens when I look at my source tree, suddenly the commit history of team project repo appears in my source tree.

How can I make a successful commit/push to my team project repo?

1

There are 1 answers

0
matt On

That is not how you contribute to the original of a forked repo.

Instead, you push the new branch to your fork. Then, on GitHub, you ask for a pull request from your new branch in your fork to an existing branch of the original repo. (This is a GitHub feature; you cannot do it thru Git, as it is not a Git feature at all. Git knows nothing of forks or pull requests.)

Alternatively, if you are a fully authorized team member, you do not fork at all. You simply clone the team repo to start with and push to it directly (and typically you will then make a pull request at GitHub).