Difference between revisions of "Git"
(added a short tutorial how to push a new feature) |
|||
Line 179: | Line 179: | ||
Check out the links at the end of the page for more git options. | Check out the links at the end of the page for more git options. | ||
</td></tr></table> | </td></tr></table> | ||
+ | |||
+ | ===Developing a new feature or bug fix using git=== | ||
+ | |||
+ | It is always a good idea to create a new branch for a new feature or a big fix you are working on. So first, let's make sure you have the most up-to-date source code. We assume, that you added BaseX as upstream repository as described above and you are currently in the ''master'' branch: | ||
+ | |||
+ | <pre class="brush:shell"> | ||
+ | $ git pull upstream master | ||
+ | </pre> | ||
+ | |||
+ | Now, we create a new branch, based on the master branch | ||
+ | |||
+ | <pre class="brush:shell"> | ||
+ | $ git checkout -b new-feature | ||
+ | Switched to a new branch 'new-feature' | ||
+ | </pre> | ||
+ | |||
+ | Your are now automatically switched to the ''new-feature'' branch. Now you can make all your changes in one or several commits. You can commit all changes using | ||
+ | |||
+ | <pre class="brush:shell"> | ||
+ | $ git commit -a | ||
+ | </pre> | ||
+ | |||
+ | Now, you want to push these changes to the repository on GitHub. Remember, that up to now your changes just reside on your local drive, so now you want to push it to your remote fork of BaseX. Simply do: | ||
+ | |||
+ | <pre class="brush:shell"> | ||
+ | $ git push origin new-featuCounting objects: 318, done. | ||
+ | Delta compression using up to 4 threads. | ||
+ | Compressing objects: 100% (107/107), done. | ||
+ | Writing objects: 100% (154/154), 22.96 KiB | 0 bytes/s, done. | ||
+ | Total 154 (delta 93), reused 81 (delta 26) | ||
+ | To git@github.com:$username/basex.git | ||
+ | * [new branch] new-feature -> new-featurere | ||
+ | </pre> | ||
+ | |||
+ | You can now use your web browser and go to your fork of BaseX. You will see the following message: | ||
+ | |||
+ | [[File:Git11.png]] | ||
+ | |||
+ | You can now click the "Compare & pull request" button. You can now review the changes you are going to push. | ||
+ | |||
+ | '''Please review them carefully. Also, please give a meaningful comment so we can quickly determine what your changes are doing.''' After clicking the "Create Pull request" button you are done and we will review your changes and either merge the pull request or get back to you. | ||
+ | |||
==Need help using git?== | ==Need help using git?== |
Revision as of 11:13, 29 September 2014
This page is part of the Developer Section. It describes how to use git to manage the BaseX sources.
Contents
- 1 Using Git to contribute to BaseX
- 2 Using Git & Eclipse
- 3 Using Git on Command-Line
- 3.1 Preparation
- 3.2 Clone Your Personal Repository
- 3.3 List Remote Repositories
- 3.4 List Local Changes
- 3.5 Commit to Local Repository
- 3.6 Pushing Local Changes to Remote Repository
- 3.7 Pulling Changes from Remote Repository
- 3.8 Add BaseXdb Upstream Repository
- 3.9 Pulling Changes from Upstream to Local Repository
- 3.10 Developing a new feature or bug fix using git
- 4 Need help using git?
Using Git to contribute to BaseX
Our team uses git and GitHub to manage the source code. All team members have read+write access to the repository, and external contributors are welcome to fork the project.
Git makes it easy to retain a full copy of the repository for yourself. To get started and running, simply fork BaseX:
- Head over to https://github.com and create an account
- Fork https://github.com/BaseXdb/basex, so you have a version on your own
- The forked project can then be cloned on your local machine, and changes can be pushed back to your remote repository
- Open Eclipse
- Install egit (Eclipse: Help → Marketplace → Search for egit or get it from http://www.eclipse.org/egit/)
Using Git & Eclipse
To clone the project from within Eclipse, you may need to install EGit first (Eclipse: Help → Marketplace → Search for egit or get it from http://www.eclipse.org/egit/).
Clone
Create the project
EGit & SSHEGit uses the JSch library which is, however, reported to have problems with RSA SSH keys in linux and possibly other platforms. A solution would be to use the variable GIT_SSH and assign it a path to the native SSH executable. According to this change in EGit, the plugin will try to use a native SSH implementation instead of JSch (this, however, may not always work either :( ). Using Git on Command-LineNote: this is not intended to be a complete git reference; it's purpose is to quickly introduce BaseX developers to the most commonly used git commands in the context of the BaseX project. Preparation
Clone Your Personal Repository$ git clone git@github.com:$username/$project.git Cloning into $project... Enter passphrase for key '/home/user/.ssh/id_rsa': ... $ ls -d -1 $PWD/* /home/user/myprojects/$project Note that git automatically creates a directory where the repository content will be checked out. List Remote Repositories$ git remote -v origin git@github.com:$username/$project.git (fetch) origin git@github.com:$username/$project.git (push) Currently, there is only one remote repository; it is automatically registered during the clone operation. Git remembers this repository as the default repository for push/pull operations. List Local ChangesAfter some files have been changed locally, the changes can be seen as follows: $ git diff diff --git a/readme.txt b/readme.txt index fabaeaa..cd09568 100644 --- a/readme.txt +++ b/readme.txt @@ -49,6 +49,10 @@ ADDING CHECKSTYLE -------------------------------------------------------------- - Enter the URL: http://eclipse-cs.sourceforge.net/update - Follow the installation procedure and restart Eclipse +USING GIT ---------------------------------------------------------------------- Any kind of feedback is welcome; please check out the online documentation at Commit to Local RepositoryNote: this commit operation does not commit into the remote repository! First, it is needed to select the modified files which should be committed: $ git add readme.txt Then perform the actual commit: $ git commit [master 0fde1fb] Added TODO in section "USING GIT" 1 files changed, 4 insertions(+), 0 deletions(-) Before executing the actual commit, git will open the default shell editor (determined using the $EDITOR variable, usually vi) to enter a message describing the commit changes. Alternative way is to commit all changed files, i. e. it is not needed to explicitly add the changed files: $ git commit -a [master 0fde1fb] Added TODO in section "USING GIT" 1 files changed, 4 insertions(+), 0 deletions(-) Pushing Local Changes to Remote Repository$ git push Enter passphrase for key '/home/user/.ssh/id_rsa': Everything up-to-date Pulling Changes from Remote Repository$ git pull Enter passphrase for key '/home/user/.ssh/id_rsa': Already up-to-date. Add BaseXdb Upstream RepositoryThe upstream repository is the one from which the BaseX releases are made and the one from which the personal repository was forked. $ git remote add upstream git@github.com:BaseXdb/$project.git $ git remote -v origin git@github.com:$username/$project.git (fetch) origin git@github.com:$username/$project.git (push) upstream git@github.com:BaseXdb/$project.git (fetch) upstream git@github.com:BaseXdb/$project.git (push) Pulling Changes from Upstream to Local RepositoryWhen some changes are made in the upstream repository, they can be pulled to the local repository as follows: $ git pull upstream master Enter passphrase for key '/home/user/.ssh/id_rsa': From github.com:BaseXdb/$project * branch master -> FETCH_HEAD Already up-to-date. The changes can then be pushed in the personal repository: $ git push Check out the links at the end of the page for more git options. |
Developing a new feature or bug fix using git
It is always a good idea to create a new branch for a new feature or a big fix you are working on. So first, let's make sure you have the most up-to-date source code. We assume, that you added BaseX as upstream repository as described above and you are currently in the master branch:
$ git pull upstream master
Now, we create a new branch, based on the master branch
$ git checkout -b new-feature Switched to a new branch 'new-feature'
Your are now automatically switched to the new-feature branch. Now you can make all your changes in one or several commits. You can commit all changes using
$ git commit -a
Now, you want to push these changes to the repository on GitHub. Remember, that up to now your changes just reside on your local drive, so now you want to push it to your remote fork of BaseX. Simply do:
$ git push origin new-featuCounting objects: 318, done. Delta compression using up to 4 threads. Compressing objects: 100% (107/107), done. Writing objects: 100% (154/154), 22.96 KiB | 0 bytes/s, done. Total 154 (delta 93), reused 81 (delta 26) To git@github.com:$username/basex.git * [new branch] new-feature -> new-featurere
You can now use your web browser and go to your fork of BaseX. You will see the following message:
You can now click the "Compare & pull request" button. You can now review the changes you are going to push.
Please review them carefully. Also, please give a meaningful comment so we can quickly determine what your changes are doing. After clicking the "Create Pull request" button you are done and we will review your changes and either merge the pull request or get back to you.
Need help using git?
Installing
For information on how to install git on various platforms please refer to: GitHub: git Installation Guide