Open source Java projects: GitHub

A guide to social coding with Git and GitHub

1 2 Page 2
Page 2 of 2

Listing 2. More common Git commands

usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           [-c name=value] [--help]
           <command> [<args>]

The most commonly used git commands are:add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG     

Update and commit

The ability to make changes locally and then push them into the repository is a powerful feature of GitHub. For instance, I recently noticed that my GitHub project geek-util uses JUnit 4.6 and decided to upgrade to v4.10. I started by updating my POM file locally to include JUnit 4.10. In order to review the differences between my local repository and the code I'm working on I executed the git diff command:

Listing 3. Diff review

$ git diff

index d1c3066..5fe2f4f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,7 +63,7 @@
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.6</version>
+            <version>4.10</version>
             <scope>test</scope>
         </dependency>
         <dependency>

The minus sign (-) shows the value of the line in the repository and the plus sign (+) shows the value in my staging environment, so it's obvious that I updated JUnit from 4.6 to 4.10. My next step is to commit the change to my local repository, which I can do with the git add and git commit commands.

Listing 4. Add and commit

$ git add pom.xml
$ git commit -m "Updated JUnit from version 4.6 to 4.10"
[master 413e4ec] Updated JUnit from version 4.6 to 4.10
 1 files changed, 1 insertions(+), 1 deletions(-)

With the commit stored locally my final step is to push this file up to GitHub using git push:

Listing 5. Push to GitHub

$ git push -u origin master
Username: 
Password: 
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 332 bytes, done.
Total 3 (delta 1), reused 0 (delta 0)
To https://github.com/geekcap/geek-util.git
   ed80e8e..413e4ec  master -> master
Branch master set up to track remote branch master from origin.

On the GitHub website I can now see the updated file, as shown in Figure 7.

Figure 7. Reviewing committed changes (click to enlarge)

In conclusion

GitHub is a social networking site and source code hosting repository for software developers dedicated to promoting and supporting open source projects. It allows you to freely host your own open source projects, as well as hosting commercial private projects for a nominal fee. In GitHub you can easily find existing projects based on popularity, search criteria, or programming language preference. You can also follow the progress of software projects and individual developers.

This edition of Open source Java projects has reviewed what GitHub is and how it works, provided a brief overview of the Git distributed version control system, and demonstrated how to create and set up a GitHub repository. I concluded with an example demonstrating the process of modifying, committing, and pushing changes to GitHub.

Hopefully this overview has given you a taste for what Git and GitHub have to offer. There is a lot more to learn, so see the Resources section for additional reading.

Steven Haines is a technical architect at Kit Digital, currently working onsite at Disney in Orlando. He is the founder of www.geekcap.com, an online education website, and has written hundreds of Java-related articles as well as three books: Java 2 From Scratch, Java 2 Primer Plus, and Pro Java EE Performance Management and Optimization. He lives with his wife and two children in Apopka, Florida.

Learn more about this topic

1 2 Page 2
Page 2 of 2