The simplest solution is to use one of the Github libraries. If you are interested in Java then you need to use this one.
First you need to authenticate using your Github account. Here is the sample from readme:
//Basic authentication
GitHubClient client = new GitHubClient();
client.setCredentials("user", "passw0rd");
//OAuth2 token authentication
GitHubClient client = new GitHubClient();
client.setOAuth2Token("SlAV32hkKG");
Then it depends on how you want to upload a document to Github. The simplest is to create a Gist. To do it use the following code:
GistFile file = new GistFile();
file.setContent("System.out.println("Hello World");");
Gist gist = new Gist();
gist.setDescription("Prints a string to standard out");
gist.setFiles(Collections.singletonMap("Hello.java", file));
GistService service = new GistService();
service.getClient().setCredentials("user", "passw0rd");
gist = service.createGist(gist); //returns the created gist
Note Gists are publicly available so if you want to make it private you need to do it explicitly
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…