Skip to content

Instantly share code, notes, and snippets.

@oculushut
Last active March 20, 2020 19:25
Show Gist options
  • Save oculushut/2413a93f311980f18910 to your computer and use it in GitHub Desktop.
Save oculushut/2413a93f311980f18910 to your computer and use it in GitHub Desktop.
Using JGit in Windows
1. Download jgit.sh from here: https://eclipse.org/jgit/download/
(Yes -> it's a file with a .sh extension and we want to work in Windows, but download it!)
2. Rename the downloaded file to something easier to deal with. E.g. "jgit.sh"
3. Create a new file called jgit.bat and stick it in the same folder as jgit.sh.
4. Type the following into the jgit.bat file:
java -cp %~dp0\jgit.sh org.eclipse.jgit.pgm.Main %*
//This will use java to look for the starting
//point to start an application whose code is
//held within the Main class which belongs to
//the org.eclipse.jgit.pgm package. All this is
//held within the jgit.sh file...
//%* means "use all the arguments from command line prompt here".
//%~dp0\ resolves to the folder that the batch script resides within
//Add the jgit.bat file to the PATH environmental variable in Windows so that it can be called
//from anywhere.
5. The code inside the Main instance will look for arguments
that are passed in during runtime. Here are the options:
jgit --git-dir GIT_DIR --help (-h) --show-stack-trace --version command [ARG ...]
The most commonly used commands are:
add Add file contents to the index
archive zip up files from the named tree
branch List, create, or delete branches
checkout Checkout a branch to the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
config Get and set repository or global options
daemon Export repositories over git://
describe Show the most recent tag that is reachable from a commit
diff Show diffs
fetch Update remote refs from another repository
gc Cleanup unnecessary files and optimize the local repository
init Create an empty git repository
log View commit history
ls-remote List references in a remote repository
ls-tree List the contents of a tree object
merge Merges two development histories
push Update remote repository from local refs
reflog Manage reflog information
repo Parse a repo manifest file and add submodules
reset Reset current HEAD to the specified state
rm Stop tracking a file
show display one commit
status Show the working tree status
tag Create a tag
version Display the version of jgit
7. E.g. you can now execute the following to get the version!
F:\#Downloads\JGit>jgit version
F:\#Downloads\JGit>java -cp jgit.sh org.eclipse.jgit.pgm.Main version
jgit version 4.2.0.201601211800-r
8. Add the folder that you have created the jgit.bat file into your PATH environmental variable
9. Now create a new file called "secret" and add in the following info from your AWS account:
accesskey: XXXXXXXXXXXX
secretkey: XXXXXXXXXXXX
acl: private
You can get the accesskey and secretkey info from your AWS account.
Place this file in your Windows user folder... e.g. C:\Users\[username]
Make sure the user account you are using has all the appropriate permissions! In particular, check out these examples:
http://blogs.aws.amazon.com/security/post/Tx3VRSWZ6B3SHAV/Writing-IAM-Policies-How-to-grant-access-to-an-Amazon-S3-bucket
Don't get caught out by not including the permissions for the bucket as well as the content of the bucket!!
10. Within your git repo, use regular git to create a remote which points to the S3 bucket. E.g.:
git remote add s3 amazon-s3://secret@foo.gitrepos/repo
If you want to amend the URL later then just use the set-url command:
git remote set-url s3 amazon-s3://secret@foo.gitrepos/repo
11. Push up to bucket with jgit!
jgit push s3 refs/heads/master
12. To clone on another machine with jgit...
jgit clone amazon-s3://secret@foo.gitrepos/repo
@AndreMikulec
Copy link

@oculushut,

After I create the jgit.bat file . . .

:: Using JGit in Windows
:: https://gist.github.com/oculushut/2413a93f311980f18910#file-jgit-L2

java -cp %~dp0\jgit.sh org.eclipse.jgit.pgm.Main %*

I try to run it.
I get the following error.

C:\Users\ComputerUser\Documents>jgit --help

C:\Users\ComputerUser\Documents>java -cp C:\Users\ComputerUser\Documents\\jgit.sh org.eclipse.jgit.pgm.Main --help
Error: Could not find or load main class org.eclipse.jgit.pgm.Main

What do I do next.
Thanks,
Andre
Andre_Mikulec@Hotmail.com

@AndreMikulec
Copy link

AndreMikulec commented Jan 10, 2020

@oculushut,

Never mind,

From

Using Git on Windows without any of the Cygwin/msysgit nonsense
Sep 13, 2010 • sandeep
http://www.lambdacurry.com/2010/09/using-git-on-windows-without-any-of-the-cygwinmsysgit-nonsense/

and from the comment of Afriza N. Arief
the following works

C:\Users\ComputerUser\Documents>java -jar org.eclipse.jgit.pgm-5.6.0.201912101111-r.sh version
jgit version 5.6.0.201912101111-r

C:\Users\ComputerUser\Documents>java -jar org.eclipse.jgit.pgm-5.6.0.201912101111-r.sh
jgit --git-dir GIT_DIR --help (-h) --show-stack-trace --version command [ARG ...]

The most commonly used commands are:
add Add file contents to the index
archive Zip up files from the named tree
branch List, create, or delete branches
checkout Check out a branch to the working tree
clean Remove untracked files from the working tree
clone Clone a repository into a new directory
commit Record changes to the repository
config Get and set repository or global options
convert-ref-storage Convert ref storage to reftable
daemon Export repositories over git://
debug-lfs-store Run LFS Store in a given directory
describe Show the most recent tag that is reachable from a commit
diff Show diffs
fetch Update remote refs from another repository
gc Cleanup unnecessary files and optimize the local repository
init Create an empty git repository
log View commit history
ls-files Show information about files in the index and the working tree
ls-remote List references in a remote repository
ls-tree List the contents of a tree object
merge Merges two development histories
push Update remote repository from local refs
reflog Manage reflog information
repo Parse a repo manifest file and add submodules
reset Reset current HEAD to the specified state
rm Stop tracking a file
show Display one commit
status Show the working tree status
tag Create a tag
version Display the version of jgit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment