Using Github tutorial. This tutorial explains how to use GitHub.
1.1. What is GitHub?
GitHub is a popular hosting provider for Git repositories. GitHub provides additional services around these repositories. For example, it provides an issue tracker for each repository, build server integration and more.
GitHub supports that repositories can be cloned to a new Git repository hosted at Github. GitHub uses the term fork or forking for creating such clones.
GitHub provides free hosting for publicly visible Git repositories. A public repository can be cloned by other people at any point in time.
If the repository should not be visible to everyone, Git allows to create private repositories, but you must pay for this service a monthly rate. Private repository allows you to specify the people which have access to the repository and to define their access rights.
GitHub can be found under the following URL: GitHub
If you create an account at GitHub, you can create a repository. After creating a repository at GitHub, you will get a description of all the commands you need to execute to upload your project to GitHub. Follow the instructions below.
These instructions will be similar to the following commands.
# global setup: # set up git git config --global user.name "Your Name" git config --global user.email firstname.lastname@example.org # next steps for a new repository mkdir gitbook cd gitbook git init touch README git add README git commit -m 'first commit' git remote add origin email@example.com:vogella/gitbook.git git push -u origin master # alternatively for an existing Git repo # add remote and push cd existing_git_repo git remote add origin firstname.lastname@example.org:vogella/gitbook.git git push -u origin master
GitHub allows you to use SSH based or HTTPS based authentication to access your repositories. To clone, pull or fetch from a public available repository no authentication is required.
1.2. Create repository in GitHub
Once you create a user at Github, you can create a new public repository. For example, the following screenshots demonstrate the creation of the de.vogella.git.github repository.
After creation of your new repository GitHub displays the information what you have to do if you want to connect to this repository via the command line.
1.3. Merging pull request at GitHub
GitHub uses Pull requests for contributions.
The typical workflow in GitHub is to fork a repository, create changes in your fork and send a pull request to the origin repository via the GitHub webinterface.
GitHub makes is easy to fork a repository via its web interface. Simply click the Fork button of a repository of your choice.
You can now clone this fork to your local development environment and push the changes to this fork at GitHub.
Afterwards you can create a pull request for the repository you forked from. Your repository is the fork as highlighted in the screenshot. Press Pull Requests to see existing and create new pull requests.
Click New pull request to create a new one.
On the next screen you can specify the direction of the pull request and the branches by selecting the Edit button.
If the owner of the repository accepts your pull request, your changes are integrated into the original repository.
1.4. Locally evaluating Github pull requests
You can also pull the changes in a Github pull request into your local Git repository to test it. Each pulll request has a link which once clicked shows you the corresponding commands.
2. Closing issues with commit messages
Github allows you to close issues with commit messages by using special keywords. Github will put a link to the closing commit into the specified issue. While it is possible to use this syntax anywhere in the commit message it is preferable to put it into the commit subject. This way it is easier to see which commit closes which issue.
2.1. Closing issues in the same repository
To close an issues in the same repository you type in one of the keywords followed by a reference to the issue number. List of possible keywords:
This is a commit message that would close issue 42 in the same repository:
Fixes #42 - Upgrade SWT dependencies
If the issue is commited to the default branch the issue will be closed immediately. If the issue is commited to another branch then the issue will only be closed if it gets merged into the default branch. This behaviour is the same for closing issues in other repositories.
2.2. Closing issues in other repositories
The syntax to close issues in other repositories is
So our example from before would look like this for the repository
project by the user
Fixes vogellacompany/project#42 - Upgrade SWT dependencies
2.3. Closing multiple issues with one commit
If you want to close multiple issues with one commit just chain the messages together.
Each message follows the pattern
This closes #42, closes #23, and closes vogellacompany/project#42
3. Continuous Integration with Github and Jenkins via webhooks
Often we want to automatically start a build on our build system after changes to a repository.
If you want to trigger a
Jenkins build after every update on your
GitHub repository you can use
To do this navigate to the repository you want your webhook for and click on
Add Service and choose the
Jenkins (Github Plugin) integration.
The Jenkins webhook url follows the pattern
Now add the Jenkins GitHub Plugin to your Jenkins instance. Make sure you have your Jenkins build correctly configured for the GitHub repository. Navigate to the Configure page of your Jenkins build. Under "Build Triggers" choose the option "Build when a change is pushed to GitHub".
After your next commit to the repository a new Jenkins build should start automatically.
4. About this website
5. Links and Literature
5.1. vogella GmbH training and consulting support
|TRAINING||SERVICE & SUPPORT|
The vogella company provides comprehensive training and education services from experts in the areas of Eclipse RCP, Android, Git, Java, Gradle and Spring. We offer both public and inhouse training. Whichever course you decide to take, you are guaranteed to experience what many before you refer to as “The best IT class I have ever attended”.
The vogella company offers expert consulting services, development support and coaching. Our customers range from Fortune 100 corporations to individual developers.
Appendix A: Copyright and License
Copyright © 2012-2016 vogella GmbH. Free use of the software examples is granted under the terms of the EPL License. This tutorial is published under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Germany license.