Github work flow
A typical maintainer Git workflow
Practise - https://github.com/mcnallyg1/git-practice/
The first thing I do is fork the project I want to contribute to. This is done on Github most of the time, although this workflow can work on gitlab, bitbucket, or even some self hosted git platform.
Go into github.com and fork the original project say https://github.com/KevinPInscoe/AWS
This will create a fork to a new repo: https://github.com/MyGHUserName/AWS
If you look under Forks for original project you should see your forked project listed under your Github username.
Once the project on Github is forked, I clone it on my local workspace:
$ git clone https://github.com/MyGHUserName/AWS.git
Git automatically names my remote forked project origin.
$ git remote -v origin https://github.com/MyGHUserName/AWS.git (fetch) origin https://github.com/MyGHUserName/AWS.git (push)
Then I need to add an upstream reference to the original project:
$ git remote add upstream https://github.com/KevinPInscoe/AWS.git git remote -v origin https://github.com/MyGHUserName/AWS.git (fetch) origin https://github.com/MyGHUserName/AWS.git (push) upstream https://github.com/KevinPInscoe/AWS.git (fetch) upstream https://github.com/KevinPInscoe/AWS.git (push)
Now my local repository references my fork under the name origin and the original project under the name upstream.
In this workflow, I never work on the master branch. So, when I need to fix a bug for example, I create a new branch usually named after bugfix name or maybe ticket number:
$ git checkout -b bugfix
I can then make changes, test my code, make sure everything is ok, stage and commit my changes:
$ git add . $ git commit -m "commit message"
Now I need to push this local branch to my repository on Github:
$ git push -u origin bugfix
Since I forked the original project, Github knows that origin and upstream are linked. If there are no conflicts, github will show me a big green button to create a pull request. Once the pull request is created, I just have to wait for the maintainer to merge it in upstream’s master branch.
Once the merge is completed I need to sync both my local copy and my fork on github with the original project. In order to do that, on my local copy, I checkout my master branch, fetch upstream’s changes, and merge them:
$ git checkout master
$ git fetch upstream $ git merge upstream/master
Now my local master branch (Forked) is ahead of origin’s master branch, so I push those changes to Github to my forked repo to bring it current with the original repo:
$ git push
I no longer need the bugfix branches (the local one and the Github one), so I can delete those :
$ git branch -d bugfix $ git push origin -d bugfix
now, my local repository is even with both origin and upstream, and I can start again.