Today, we will see how to make updates to our Java project. We are working on this simple Java project called "MyFirstApp". We are storing this project in the Git repository called "HeadFirstJava". Anyone can see this @ https://github.com/gradney/HeadFirstJava
If you missed 'howie' (technically, "how we")...
- created a project, see a simple tutorial @ http://eclipsetutorial.sourceforge.net/totalbegginer01/lesson01.html
- created a repository in GitHub, see a simple tutorial @ https://help.github.com/articles/set-up-git
- uploaded our project into GitHub, see my blogpost @ http://g2coding.blogspot.com/2014/03/quick-learning-pushing-java-project-in.html
First, let's begin with a good practice - by seeing if anyone else updated my project in GitHub. If someone did, then I need to see what these updates are and download (or "fetch") the code updates to my local machine (and sync up my local project).
I open my GitHub Client and click the 'arrow' icon on the HeadFirstJava repository (element?)(I would say 'button', but it doesn't look like a button. It's like a hyperlink that highlights it's element block when the mouse is over it). Alright, so we opened this repo directory in GitHub Client and see no files or folders are un-synced.
Great, now we can proceed with making updates in our Java project.
In the book "Head First Java" (by Kathy Sierra & Bert Bates), we read through the pages and reach page 9. This is where my first application comes from. I will add the rest of the code into MyFirstApp program (via Eclipse). Later, I will use an editor as instructed by the authors to write my Java programs. However, this means that we also need to learn later how to use Git via Git Bash (shell commands). Until then, let's continue with the approach we already know - updating Java project in Eclipse and uploading code via GitHub Client app.
On page 9, I need to add the two statements and I do. Next, I save the updates in my project within Eclipse. My Eclipse shows me that MyFirstApp project is now different (i.e. has been updated) due to the ">" icon next to the folder and file icons of my project.
Next, right-click on "MyFirstApp.java", select Team > Commit... Add a Commit message, check the File "MyFirstApp.java" and click Commit. Now our changes are committed to our local Git repo "HeadFirstJava". Again, to upload our code updates, we open our GitHub Client app and see we are out of sync with the online repo (i.e. my GitHub's HeadFirstJava). Our GitHub Client even has a little 'arrow up' with a number inside a blue ellipse shape that notifies us that our local has an updated version compared to the program stored in our online repo. We also see what has been updated in the screen display within the GitHub Client. This is pretty cool!!! I can already see the updates without having to guess. Incredible!
Simply, click on the "sync" button and watch GitHub Client synchronize GitHub. GitHub Client's History column updates with my comments AND GitHub's HeadFirstJava repo is updated with my code. This is remarkable!
Oh crap! You know what we forgot to do? Yep, we forgot to run our program and make sure the code works before we "committed and pushed" our code to our online repo in GitHub. Well, usually we would run and test our program before "committing and pushing", but for now let's just run and test our program locally to make sure it works.
EXCELLENT! Whew, and we're lucky too (that it worked). If it didn't though, we would just make code updates, test the program, and then commit/push to GitHub repo. Well, that's it for today! Good job, pro!
Oh, just in case, here's a link to the Head First Java book @ http://www.ebooks-it.net/ebook/head-first-java-2nd-edition.