Now is a good time to commit and push the new project to GitBucket.
Right click the project in the projects pane.
Select <
Commit">>.You will see a dialog appear showing you what files are going to be added to the repository. At this point it will just be the Gradle files, and the Main
class.
You will also see a text area in which you can add a Commit Message. You should always provide a useful message that describes what you have done since you last committed.
A Git commit message is a bit like an email message. The first line represents the subject and should very briefly name the feature/bug you were working on and what action you were performing on that feature/bug (adding, fixing, refactoring, completing, ...). There should be a blank line after the first line. The rest of the message can include a more detailed description of why the commit was added. Note the use of the word 'why' rather than 'what' in the previous sentence. We can easily see what changed --- Git has many features that can show us what changed so we don't need to repeat this in the commit message. The commit message is about describing why those changes were made.
In this case, we have just created the project, so your commit message should reflect that.
Click <
>.You should see the Git log in the output pane. You will see a message at the end stating that the commit has finished. Since you are committing to the local repository in your home folder the commit should happen nearly instantly.
Open the repository browser using <
Repository > Repository Browser">>.This is a handy browser that we can use to perform operations on the entire repository rather than just the NetBeans project. If you only have one project in the repository then there is little difference. However, we can have many projects inside a single repository.
Some actions require you to use the repository browser. An example would be if you move a file from one project into another. Ideally you would commit that action in a single commit, so you would have to perform the commit on the repository rather than the projects.
This is a handy pane to keep open. We will use the repository browser to interact with GitBucket in the next step.
At this point you have only added the files to your local repository. Now we need to push the local repository into the repository on GitBucket.
Right click your repository in the repository browser and select <
Push to Upstream">>.You will be asked if you want to create a new remote master branch since the repository on GitBucket is currently empty. Click <
>.You will also be asked if you want the local master to track the remote master. Doing this makes it easy to compare the local version of the project against the remote version which allows you to see what you have changed since you last pushed. Again click <
>.Check the output pane. You should see a message stating that the push is finished.
In the repository browser, expand the <
> and <> folders under <>.You will see that currently there is only one branch in the local repository --- master
. This is the primary branch for most Git repositories --- most work will be added to this branch.
You will also see that there is a remote branch named origin/master
. This is a branch that is used to store a copy of the master that comes from GitBucket. When you pull, the master
on GitBucket is copied into this branch. This allows you to compare between the local master
and the remote master
to see what has changed since your last push/merge.
Since we told Git to make the local master track the remote master, you can see that the local master
is automatically checking itself against the origin/master
. At the moment both branches are in sync
with each other, meaning they are both identical --- you can also see that both branches have the same commit ID for their most recent commits.
Go back to the web browser and refresh the GitBucket repository page. You should now see that your repository has the NetBeans project in it. You will also see the commit message beside the files.
Explore the project by clicking the info202_project
folder. Click the <> folder. You should see your Main
class.
The general rules for committing and pushing are:
You added a new feature, or at least completed some logical milestone on your way towards completing the feature.
You fixed a bug.
You added a section to a documentation file.
You completed some other milestone, such as finishing an important class, or completing an issue.
Note that committing and pushing are different operations. Committing modifies your local repository (the version in your home folder). Pushing will push the changes in your local repository to the remote repository (GitBucket).
Put another way, committing will update the local branch. Pushing will synchronise the local branch with the remote branch on the server.
You don't have to push after every commit, but it is a good idea to push regularly so that you have a recent backup of your repository in case something horrible happens.
Before you log out and leave also make sure that you push so that you have the latest version of your code in GitBucket in case you want to continue working on it from home.