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
I'm summing up everyone's answer.
Fork
your friend's repository.git clone {URL}
.git checkout -b new_branch
.git remote add upstream {URL}
git add {file name}
or git add .
if you want to add all files.git commit -m "message"
git remote add upstream {URL of friend's repository that you have forked}
git remote -v
git push
Here you have to give your username and password.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.
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).
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.
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.