Difference between revisions of "Git"
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | This page is part of the [[Developer Section]]. It describes how to use [ | + | This page is part of the [[Developer Section]]. It describes how to use [https://git-scm.com/ git] to manage the BaseX sources. |
==Using Git to contribute to BaseX == | ==Using Git to contribute to BaseX == | ||
Line 12: | Line 12: | ||
==Using Git & Eclipse== | ==Using Git & Eclipse== | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===Clone=== | ===Clone=== | ||
* In the '''Package Explorer''' to the left, use right-click and choose '''Import...''' | * In the '''Package Explorer''' to the left, use right-click and choose '''Import...''' | ||
− | * Select '''Projects from Git''' and click '''Next | + | * 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 | * 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}}. | * 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) | * 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'''". | * Now choose a location where the local repository is stored: Create <workspace>'''/repos/BaseX''' and click "'''Finish'''". | ||
+ | |||
+ | <gallery> | ||
+ | File:Git01.png|Package Explorer | ||
+ | File:Git02.png|Projects from Git | ||
+ | File:Git03.png|Clone | ||
+ | File:Git04.png|GitHub URI | ||
+ | File:Git05.png|Select Branch | ||
+ | File:Git06.png|Location | ||
+ | </gallery> | ||
===Create the project === | ===Create the project === | ||
Line 41: | Line 36: | ||
* 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. | * 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 | * Click next to select the Project to import | ||
− | * Check "basex" to | + | * Check "basex" to check out and click finish |
* You are now ready to contribute. | * You are now ready to contribute. | ||
+ | |||
+ | <gallery> | ||
+ | File:Git07.png|Select Repository | ||
+ | File:Git08.png|Import existing Projects | ||
+ | File:Git09.png|Select basex Project | ||
+ | </gallery> | ||
===EGit & SSH=== | ===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 {{ | + | 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 {{Code|GIT_SSH}} variable. |
==Using Git on Command-Line== | ==Using Git on Command-Line== | ||
− | '''Note''': this is not intended to be a complete git reference; | + | '''Note''': this is not intended to be a complete git reference; its purpose is to quickly introduce BaseX developers to the most commonly used git commands in the context of the BaseX project. |
===Preparation=== | ===Preparation=== | ||
# Create a GitHub user account: [https://github.com/signup/free here] (your github user name will be referenced as $username) | # 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 [ | + | # Set up SSH access to GitHub as described [https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh here] |
# Create a fork of one of the BaseXdb projects (it will be referenced as $project) | # 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) | # Choose a directory where the project will be created and make it your working directory (e. g. /home/user/myprojects) | ||
Line 61: | Line 62: | ||
===Clone Repository=== | ===Clone Repository=== | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git clone git@github.com:$username/$project.git | $ git clone git@github.com:$username/$project.git | ||
Cloning into $project... | Cloning into $project... | ||
Line 69: | Line 70: | ||
$ ls -d -1 $PWD/* | $ ls -d -1 $PWD/* | ||
/home/user/myprojects/$project | /home/user/myprojects/$project | ||
− | </ | + | </syntaxhighlight> |
Note that git automatically creates a directory where the repository content will be checked out. | Note that git automatically creates a directory where the repository content will be checked out. | ||
===List Remote Repositories=== | ===List Remote Repositories=== | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git remote -v | $ git remote -v | ||
origin git@github.com:$username/$project.git (fetch) | origin git@github.com:$username/$project.git (fetch) | ||
origin git@github.com:$username/$project.git (push) | origin git@github.com:$username/$project.git (push) | ||
− | </ | + | </syntaxhighlight> |
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. | 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. | ||
Line 84: | Line 85: | ||
After some files have been changed locally, the changes can be seen as follows: | After some files have been changed locally, the changes can be seen as follows: | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git diff | $ git diff | ||
diff --git a/readme.txt b/readme.txt | diff --git a/readme.txt b/readme.txt | ||
Line 97: | Line 98: | ||
Any kind of feedback is welcome; please check out the online documentation at | Any kind of feedback is welcome; please check out the online documentation at | ||
− | </ | + | </syntaxhighlight> |
===Commit to Local Repository=== | ===Commit to Local Repository=== | ||
Line 104: | Line 105: | ||
First, it is needed to select the modified files which should be committed: | First, it is needed to select the modified files which should be committed: | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git add readme.txt | $ git add readme.txt | ||
− | </ | + | </syntaxhighlight> |
Then perform the actual commit: | Then perform the actual commit: | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git commit | $ git commit | ||
[master 0fde1fb] Added TODO in section "USING GIT" | [master 0fde1fb] Added TODO in section "USING GIT" | ||
1 files changed, 4 insertions(+), 0 deletions(-) | 1 files changed, 4 insertions(+), 0 deletions(-) | ||
− | </ | + | </syntaxhighlight> |
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. | 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: | Alternative way is to commit all changed files, i. e. it is not needed to explicitly add the changed files: | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git commit -a | $ git commit -a | ||
[master 0fde1fb] Added TODO in section "USING GIT" | [master 0fde1fb] Added TODO in section "USING GIT" | ||
1 files changed, 4 insertions(+), 0 deletions(-) | 1 files changed, 4 insertions(+), 0 deletions(-) | ||
− | </ | + | </syntaxhighlight> |
===Pushing Changes to Remote Repository=== | ===Pushing Changes to Remote Repository=== | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git push | $ git push | ||
Enter passphrase for key '/home/user/.ssh/id_rsa': | Enter passphrase for key '/home/user/.ssh/id_rsa': | ||
Everything up-to-date | Everything up-to-date | ||
− | </ | + | </syntaxhighlight> |
===Pulling Changes from Remote Repository=== | ===Pulling Changes from Remote Repository=== | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git pull | $ git pull | ||
Enter passphrase for key '/home/user/.ssh/id_rsa': | Enter passphrase for key '/home/user/.ssh/id_rsa': | ||
Already up-to-date. | Already up-to-date. | ||
− | </ | + | </syntaxhighlight> |
===Add Upstream Repository=== | ===Add Upstream Repository=== | ||
Line 143: | Line 144: | ||
The upstream repository is the one from which the BaseX releases are made and the one from which the personal repository was forked. | The upstream repository is the one from which the BaseX releases are made and the one from which the personal repository was forked. | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git remote add upstream git@github.com:BaseXdb/$project.git | $ git remote add upstream git@github.com:BaseXdb/$project.git | ||
Line 151: | Line 152: | ||
upstream git@github.com:BaseXdb/$project.git (fetch) | upstream git@github.com:BaseXdb/$project.git (fetch) | ||
upstream git@github.com:BaseXdb/$project.git (push) | upstream git@github.com:BaseXdb/$project.git (push) | ||
− | </ | + | </syntaxhighlight> |
===Pulling Changes from Upstream to Local Repository=== | ===Pulling Changes from Upstream to Local Repository=== | ||
Line 157: | Line 158: | ||
When some changes are made in the upstream repository, they can be pulled to the local repository as follows: | When some changes are made in the upstream repository, they can be pulled to the local repository as follows: | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git pull upstream master | $ git pull upstream master | ||
Enter passphrase for key '/home/user/.ssh/id_rsa': | Enter passphrase for key '/home/user/.ssh/id_rsa': | ||
Line 163: | Line 164: | ||
* branch master -> FETCH_HEAD | * branch master -> FETCH_HEAD | ||
Already up-to-date. | Already up-to-date. | ||
− | </ | + | </syntaxhighlight> |
The changes can then be pushed in the personal repository: | The changes can then be pushed in the personal repository: | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git push | $ git push | ||
− | </ | + | </syntaxhighlight> |
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. | ||
Line 177: | Line 178: | ||
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: | 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: | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git pull upstream master | $ git pull upstream master | ||
− | </ | + | </syntaxhighlight> |
Now, we create a new branch, based on the master branch | Now, we create a new branch, based on the master branch | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git checkout -b new-feature | $ git checkout -b new-feature | ||
Switched to a new branch 'new-feature' | Switched to a new branch 'new-feature' | ||
− | </ | + | </syntaxhighlight> |
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 | 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 | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git commit -a | $ git commit -a | ||
− | </ | + | </syntaxhighlight> |
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: | 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: | ||
− | < | + | <syntaxhighlight lang="shell"> |
$ git push origin new-feature | $ git push origin new-feature | ||
Counting objects: 318, done. | Counting objects: 318, done. | ||
Line 205: | Line 206: | ||
To git@github.com:$username/basex.git | To git@github.com:$username/basex.git | ||
* [new branch] new-feature -> new-feature | * [new branch] new-feature -> new-feature | ||
− | </ | + | </syntaxhighlight> |
You can now use your web browser and go to your fork of BaseX. You will see the following message: | You can now use your web browser and go to your fork of BaseX. You will see the following message: | ||
Line 217: | Line 218: | ||
==Links== | ==Links== | ||
− | * [ | + | * [https://docs.github.com/en/github/getting-started-with-github/set-up-git GitHub: git Installation Guide] |
− | * [ | + | * [https://help.github.com/ Comprehensive Getting Starting Guide on GitHub] |
− | * [ | + | * [https://book.git-scm.com/ The git book] |
− |
Revision as of 13:27, 29 July 2020
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 Repository
- 3.3 List Remote Repositories
- 3.4 List Local Changes
- 3.5 Commit to Local Repository
- 3.6 Pushing Changes to Remote Repository
- 3.7 Pulling Changes from Remote Repository
- 3.8 Add Upstream Repository
- 3.9 Pulling Changes from Upstream to Local Repository
- 3.10 Developing a new feature or bug fix
- 4 Links
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
Using Git & Eclipse
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 check out 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 GIT_SSH
variable.
Using Git on Command-Line
Note: this is not intended to be a complete git reference; its 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: here (your github user name will be referenced as $username)
- Set up SSH access to GitHub as described 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
<syntaxhighlight lang="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 </syntaxhighlight> Note that git automatically creates a directory where the repository content will be checked out.
List Remote Repositories
<syntaxhighlight lang="shell"> $ git remote -v origin git@github.com:$username/$project.git (fetch) origin git@github.com:$username/$project.git (push) </syntaxhighlight> 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: <syntaxhighlight lang="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
</syntaxhighlight>
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: <syntaxhighlight lang="shell"> $ git add readme.txt </syntaxhighlight>
Then perform the actual commit: <syntaxhighlight lang="shell"> $ git commit [master 0fde1fb] Added TODO in section "USING GIT"
1 files changed, 4 insertions(+), 0 deletions(-)
</syntaxhighlight> 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: <syntaxhighlight lang="shell"> $ git commit -a [master 0fde1fb] Added TODO in section "USING GIT"
1 files changed, 4 insertions(+), 0 deletions(-)
</syntaxhighlight>
Pushing Changes to Remote Repository
<syntaxhighlight lang="shell"> $ git push Enter passphrase for key '/home/user/.ssh/id_rsa': Everything up-to-date </syntaxhighlight>
Pulling Changes from Remote Repository
<syntaxhighlight lang="shell"> $ git pull Enter passphrase for key '/home/user/.ssh/id_rsa': Already up-to-date. </syntaxhighlight>
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.
<syntaxhighlight lang="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) </syntaxhighlight>
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:
<syntaxhighlight lang="shell"> $ 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. </syntaxhighlight>
The changes can then be pushed in the personal repository: <syntaxhighlight lang="shell"> $ git push </syntaxhighlight>
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:
<syntaxhighlight lang="shell"> $ git pull upstream master </syntaxhighlight>
Now, we create a new branch, based on the master branch
<syntaxhighlight lang="shell"> $ git checkout -b new-feature Switched to a new branch 'new-feature' </syntaxhighlight>
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
<syntaxhighlight lang="shell"> $ git commit -a </syntaxhighlight>
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:
<syntaxhighlight lang="shell"> $ 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
</syntaxhighlight>
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.