Difference between revisions of "Git"

From BaseX Documentation
Jump to navigation Jump to search
(23 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
This page is part of the [[Developer Section]]. It describes how to use [http://git-scm.com/ git] to manage the BaseX sources.
 +
 
==Using Git to contribute to BaseX ==
 
==Using Git to contribute to BaseX ==
  
Our team uses git and [https://github.com/BaseXdb/BaseX GitHub] to manage the source code.
+
Our team uses git and [https://github.com 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
 +
 
 +
==Using Git & Eclipse==
 +
 
 +
<table cellspacing='0' cellpadding='0' width='100%'>
 +
<tr><td valign='top'>
 +
[[File:Git01.png|border|300px|left]]
 +
[[File:Git02.png|border|300px|left]]
 +
[[File:Git03.png|border|300px|left]]
 +
[[File:Git04.png|border|300px|left]]
 +
[[File:Git05.png|border|300px|left]]
 +
[[File:Git06.png|border|300px|left]]
 +
[[File:Git07.png|border|300px|left]]
 +
[[File:Git08.png|border|300px|left]]
 +
[[File:Git09.png|border|300px|left]]
 +
[[File:Git10.png|border|300px|left]]
 +
</td><td valign='top'>
 +
 
 +
===Clone===
 +
 
 +
* In the '''Package Explorer''' to the left, use right-click and choose '''Import...'''
 +
* Select '''Projects from Git''' and click '''Next &gt;'''
 +
* Choose the '''Clone''' option to create a local copy of the remote repository. This copy will include the full project history
 +
* Copy & Paste the GitHub URI in the Location field. If you want to use SSH, make sure you provided GitHub with your public key to allow write-access. If in doubt, use the https URI and authenticate yourself with your GitHub credentials. The read-only URI of the repository is {{Code|https://github.com/BaseXdb/basex.git}}.
 +
* Select the master branch (or arbitrary branches you like)
 +
* Now choose a location where the local repository is stored: Create &lt;workspace&gt;'''/repos/BaseX''' and click "'''Finish'''".
 +
 
 +
===Create the project ===
 +
 
 +
* Select our newly cloned repository and click Next
 +
* Select "'''Import Existing Projects'''" and depending on your Eclipse version enable automatic sharing. More recent versions will not offer this feature as sharing is enabled by default.
 +
* Click next to select the Project to import
 +
* Check "basex" to checkout and click finish
 +
* You are now ready to contribute.
 +
 
 +
===EGit & SSH===
 +
 
 +
The Eclipse git plugin uses the [http://www.jcraft.com/jsch JSch] library, which had [https://bugs.eclipse.org/bugs/show_bug.cgi?id=326526 problems with RSA SSH keys] in Linux and possibly other platforms. If the problem persists, the path to the native SSH executable can be assigned to the {{Cpde|GIT_SSH}} variable. According to [http://egit.eclipse.org/r/#change,2037 this] change in EGit, the plugin will try to use a native SSH implementation instead of JSch.
 +
 
 +
==Using Git on Command-Line==
 +
 
 +
'''Note''': 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===
 +
 
 +
# Create a GitHub user account: [https://github.com/signup/free here] (your github user name will be referenced as $username)
 +
# Set up SSH access to GitHub as described [http://help.github.com/key-setup-redirect here]
 +
# Create a fork of one of the BaseXdb projects (it will be referenced as $project)
 +
# Choose a directory where the project will be created and make it your working directory (e. g. /home/user/myprojects)
 +
 
 +
===Clone Repository===
 +
 
 +
<pre class="brush:shell">
 +
$ 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
 +
</pre>
 +
Note that git automatically creates a directory where the repository content will be checked out.
 +
 
 +
===List Remote Repositories===
 +
 
 +
<pre class="brush:shell">
 +
$ git remote -v
 +
origin  git@github.com:$username/$project.git (fetch)
 +
origin  git@github.com:$username/$project.git (push)
 +
</pre>
 +
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 Changes===
 +
 
 +
After some files have been changed locally, the changes can be seen as follows:
 +
<pre class="brush:shell">
 +
$ 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
 +
</pre>
 +
 
 +
===Commit to Local Repository===
 +
 
 +
'''Note''': this commit operation does '''not''' commit into the remote repository!
 +
 
 +
First, it is needed to select the modified files which should be committed:
 +
<pre class="brush:shell">
 +
$ git add readme.txt
 +
</pre>
 +
 
 +
Then perform the actual commit:
 +
<pre class="brush:shell">
 +
$ git commit
 +
[master 0fde1fb] Added TODO in section "USING GIT"
 +
1 files changed, 4 insertions(+), 0 deletions(-)
 +
</pre>
 +
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:
 +
<pre class="brush:shell">
 +
$ git commit -a
 +
[master 0fde1fb] Added TODO in section "USING GIT"
 +
1 files changed, 4 insertions(+), 0 deletions(-)
 +
</pre>
 +
 
 +
===Pushing Changes to Remote Repository===
 +
 
 +
<pre class="brush:shell">
 +
$ git push
 +
Enter passphrase for key '/home/user/.ssh/id_rsa':
 +
Everything up-to-date
 +
</pre>
 +
 
 +
===Pulling Changes from Remote Repository===
 +
 
 +
<pre class="brush:shell">
 +
$ git pull
 +
Enter passphrase for key '/home/user/.ssh/id_rsa':
 +
Already up-to-date.
 +
</pre>
 +
 
 +
===Add Upstream Repository===
 +
 
 +
The upstream repository is the one from which the BaseX releases are made and the one from which the personal repository was forked.
 +
 
 +
<pre class="brush:shell">
 +
$ 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)
 +
</pre>
 +
 
 +
===Pulling Changes from Upstream to Local Repository===
  
All team members have read+write access to the repository, external contributors are invited
+
When some changes are made in the upstream repository, they can be pulled to the local repository as follows:
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.
+
<pre class="brush:shell">
If forking sounds unfamiliar to you, we suggest to look up some of the documentation listed at the end of this page.
+
$ 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.
 +
</pre>
  
You can then build BaseX with [[Maven]]. Using Eclipse is optional.
+
The changes can then be pushed in the personal repository:
 +
<pre class="brush:shell">
 +
$ git push
 +
</pre>
  
==Using Git & Eclipse ==
+
Check out the links at the end of the page for more git options.
 +
</td></tr></table>
  
# (Optional) Head over to https://github.com/basexdb and create an account
+
===Developing a new feature or bug fix===
# Fork BaseX, so you have a version on your own
 
# Make yourself familiar with git (see the end of this page)
 
# Install egit (Eclipse: Help > Marketplace > Search for ''egit'' '''or''' get it from [http://www.eclipse.org/egit/ here])
 
# Open Eclipse
 
  
<div class="subcolumns">
+
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:
===Setup ===
 
<div class="c50l">
 
  
[[File:Git01.png|border|300px|left]] In the '''Package Explorer''' to the left use right-click and choose Import...
+
<pre class="brush:shell">
</div>
+
$ git pull upstream master
<div class="c50r">
+
</pre>
[[File:Git02.png|border|300px|left]] Select "'''Projects from Git'''" and click Next &gt;
 
</div>
 
</div>
 
<div class="subcolumns">
 
===Clone ===
 
  
<div class="c50l">
+
Now, we create a new branch, based on the master branch
[[File:Git03.png|border|300px|left]] Click "'''Clone...'''" to create a local copy of the remote repository. This copy will include the full project history
 
</div>
 
<div class="c50r">
 
[[File:Git04.png|border|300px|left]] Copy & Paste the github URI in the Location field. If you want to use SSH make sure you provided GitHub with your public key to allow write-access. If in doubt use the HTTPS URI and authenticate yourself with your GitHub credentials.
 
</div>
 
</div>
 
  
<div class="subcolumns">
+
<pre class="brush:shell">
<div class="c50l">
+
$ git checkout -b new-feature
[[File:Git05.png|border|300px|left]] Select the master branch (or arbitrary branches you like)
+
Switched to a new branch 'new-feature'
+
</pre>
</div>
 
<div class="c50r">
 
[[File:Git06.png|border|300px|left]] Now choose a location where the local repository is stored: Create &lt;workspace&gt;'''/repos/BaseX'''
 
and click "'''Finish'''".
 
 
</div>
 
</div>
 
  
<div class="subcolumns">
+
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
===Create the project ===
+
 
<div class="c50l">
+
<pre class="brush:shell">
[[File:Git07.png|border|300px|left]] Select our newly cloned repository and click Next
+
$ git commit -a
</div>
+
</pre>
<div class="c50r">
+
 
[[File:Git08.png|border|300px|left]] Select "'''Import Existing Projects'''" and depending on your Eclipse version enable automatic sharing. More recent versions will not offer this feature as sharing is enabled by default.
+
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:
+
 
Click next to select the Project to import
+
<pre class="brush:shell">
</div>
+
$ git push origin new-feature
</div>
+
Counting 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-feature
 +
</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.
  
<div class="subcolumns">
+
'''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.
<div class="c50l">
 
[[File:Git09.png|border|300px|left]] Check "basex" to checkout and click finish
 
</div>
 
<div class="c50r">
 
[[File:Git10.png|border|300px|left]] You are now ready to contribute.  
 
</div>
 
</div>
 
  
==Need help using git?==
+
==Links==
===Installing===
 
For information on how to install git on various platforms please refer to: [http://help.github.com/git-installation-redirect/  GitHub: git Installation Guide]
 
  
===Documentation===
+
* [http://help.github.com/git-installation-redirect/ GitHub: git Installation Guide]
 
* [http://help.github.com/ Comprehensive Getting Starting Guide on GitHub]
 
* [http://help.github.com/ Comprehensive Getting Starting Guide on GitHub]
 
* [http://book.git-scm.com/index.html The git book]
 
* [http://book.git-scm.com/index.html The git book]
 
* [http://gitcasts.com/ Gitcasts.com – Video Guides]
 
* [http://gitcasts.com/ Gitcasts.com – Video Guides]

Revision as of 12:17, 13 December 2017

This page is part of the Developer Section. It describes how to use git to manage the BaseX sources.

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:

  1. Head over to https://github.com and create an account
  2. Fork https://github.com/BaseXdb/basex, so you have a version on your own
  3. The forked project can then be cloned on your local machine, and changes can be pushed back to your remote repository

Using Git & Eclipse

Git01.png
Git02.png
Git03.png
Git04.png
Git05.png
Git06.png
Git07.png
Git08.png
Git09.png
Git10.png

Clone

  • In the Package Explorer to the left, use right-click and choose Import...
  • Select Projects from Git and click Next >
  • Choose the Clone option to create a local copy of the remote repository. This copy will include the full project history
  • Copy & Paste the GitHub URI in the Location field. If you want to use SSH, make sure you provided GitHub with your public key to allow write-access. If in doubt, use the https URI and authenticate yourself with your GitHub credentials. The read-only URI of the repository is https://github.com/BaseXdb/basex.git.
  • Select the master branch (or arbitrary branches you like)
  • Now choose a location where the local repository is stored: Create <workspace>/repos/BaseX and click "Finish".

Create the project

  • Select our newly cloned repository and click Next
  • Select "Import Existing Projects" and depending on your Eclipse version enable automatic sharing. More recent versions will not offer this feature as sharing is enabled by default.
  • Click next to select the Project to import
  • Check "basex" to checkout and click finish
  • You are now ready to contribute.

EGit & SSH

The Eclipse git plugin uses the JSch library, which had problems with RSA SSH keys in Linux and possibly other platforms. If the problem persists, the path to the native SSH executable can be assigned to the Template:Cpde variable. According to this change in EGit, the plugin will try to use a native SSH implementation instead of JSch.

Using Git on Command-Line

Note: 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

  1. Create a GitHub user account: here (your github user name will be referenced as $username)
  2. Set up SSH access to GitHub as described here
  3. Create a fork of one of the BaseXdb projects (it will be referenced as $project)
  4. Choose a directory where the project will be created and make it your working directory (e. g. /home/user/myprojects)

Clone 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 Changes

After 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 Repository

Note: 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 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 Upstream Repository

The 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 Repository

When 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

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-feature
Counting 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-feature

You can now use your web browser and go to your fork of BaseX. You will see the following message:

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.

Links