How to contribute to someone else's repository?

前端 未结 5 1502
小蘑菇
小蘑菇 2021-01-18 22:48

I have a friend who has a repository in his GitHub account. I want to contribute (pull/push) to the master branch (the only branch) on that repo directly.

How would

相关标签:
5条回答
  • 2021-01-18 23:29

    I'm summing up everyone's answer.

    1. Fork your friend's repository.
    2. Fire up your terminal and type git clone {URL}.
    3. Use this command to create a branch: git checkout -b new_branch.
    4. Create a new remote for the upstream repo i.e. the link of original repo with the command: git remote add upstream {URL}
    5. Do whatever changes you want in your local machine.
    6. Fire up your terminal again and type git add {file name} or git add . if you want to add all files.
    7. Then type a message git commit -m "message"
    8. Create a branch: git remote add upstream {URL of friend's repository that you have forked}
    9. For confirmation: git remote -v
    10. git push Here you have to give your username and password.
    0 讨论(0)
  • 2021-01-18 23:30

    Since you specified that you want to push directly to your friend's repo, your friend needs to add you as a collaborator in the repo settings.

    However, given your inexperience with git, it would be better to take the indirect approach: fork the repo and use pull requests to move your changes into the main repo.

    0 讨论(0)
  • 2021-01-18 23:40

    The above answers are missing details.

    Github's docs directly answer this question and clearly say the original repo should be added as another remote so the PR can be pushed, i.e.

    git remote add upstream <original_repo>
    

    Your own fork on Github can now be pushed to as "origin" (or whatever you labelled it), but the original repo can be pushed to as "upstream" (or whatever label to differentiate it from your fork).

    0 讨论(0)
  • 2021-01-18 23:46

    The right way would be to fork his repository, do your work and then create a pull request. Then he could review it and decide to merge it into his work. Here's a good description: https://guides.github.com/introduction/flow/index.html

    Edit: added a link to github.

    0 讨论(0)
  • 2021-01-18 23:50

    Agreeds with falk's answer above. Check if you are a collaborator, or can he give you an access? if not follow the below steps

    Go to your friends repo and fork his repo!!

    On your forked repo of his copy the URL

    Install git on your machine. Go to root directory on your terminal and follow the below steps

    Do:

    git clone URL
    

    now do whatever edits in your cloned repo. Say you have modified a file, readMe.txt. Since you modified it on your repo!!

    git add readMe.txt 
    

    Now you should commit the change

    git commit -m "Dude, I have modified readMe.txt"
    

    Now push:

    you need to add your remote github repo to push changes in to your forked repository

    git remote add origin https://github.com/username/myproject.git
    

    To confirm see:

    git remote -v
    

    Now after confirming, you can push the code:

    git push
    

    Git pull:

    I am assuming your friend has not added you in the list of contributors. Since you have made changes to some file, now you want to see those changes in your friends repo as well. So send him the pull request from your forked repo on to his original repo!!

    By the way this is the awesome tutorial I used when I started using Git.

    0 讨论(0)
提交回复
热议问题