Everything i describe below might be doable in a git gui. But i describe it via the command line commands because this should work for everyone. (Each gui looks different)
Atlassian has nice tutorials for git in general (Might be of some help for dealing with the git side of things.)
If you want to contribute to a repository for which you do not have write access, you need to do this via a pull request.
For that you first need to fork the repo in question. (This creates a copy of the repo in your personal github account such that you have write access to it.)
Next clone this repo to your local device.
(More detailed description of the clone command)
git clone [web address of your personal fork]
The git clone command sets up your local repo such that the so called
origin points to your personal fork.
It is advisable to also have a pointer to the repo to which you want to contribute. (Such that you can merge changes that are made by others back into your personal repo. This is especially important if you plan on contributing more than once.)
To achieve this i normally simply add a second remote called upstream.
(Atlassian tutorial about syncing)
git remote add upstream [web address of the repo you want to contribute to]
Now your local repo is setup and good to go. Lets prepare it for a new pull request.
For that you first want to sync your personal master branch with the official repo. (Not necessary for your first contribution. If you use the detached head method i describe below you do not need to do this.)
git checkout master (makes sure you are on the master branch)
git pull (makes sure your local master is in sync with your remote master)
git pull upstream/master (This gets your local master in sync with the official repo)
git push (This gets your remote master in sync as well.)
You should always create a separate branch for each pull request. So lets create a new branch.
(Atlassain what are branches)
git checkout master
git checkout -b [branch name that makes sense to you]
git branch --set-upstream [my_branch] origin/[my_branch]
Now everything is ready and you can make your changes locally.
If you are done (or want the current state saved on the server) you need to commit your changes and push them.
git commit -m "[A meaningful commit message that tells you and others what you have done.]"
If you are happy with your local changes you can create a pull request via the github web page of the repo you want to contribute to.
If a library maintainer requests changes you can simply push them to the same branch. Make sure you are on the correct branch before you start to work. The order of operations is:
git checkout [my_branch] (use the same branch name as you used above)
- do your changes
git commit -m "[Another meaningful commit message]"
With luck your contribution will be merged at the end of this process. (It looks worse than it is. It is also not the only way of doing it. Might not even be the easiest. But it is the workflow that i use.)
Detached HEAD method:
instead of keeping the master branch of your fork always in sync with the master of the official lib repo you can work from a detached head. (Don't think to much about the terminology.)
For that i assume you have added the official repo as upstream. (As described above.)
When creating a new pull request you don't do the sync step of pulling from upstream but instead you fetch the upstream master and create the new branch from this branch.
git fetch upstream
git checkout upstream/master (After that you get a message that you are in detached head. This is why i call it this way.)
git checkout -b [my_branch]
git push --set-upstream [my_branch] origin/[my_branch]
This has a lot less commands to remember. But it might be harder to understand for a beginner.