Your steps are fine. However, to throw a little, about the comments:
Commenting on steps (2) and (3) is not the best way to think about what is happening, I don't believe.
2.git add foo.java //will add it to my local repo 3.git commit -m "my changes" //commit to the local repo
The step that โaddsโ your file to the local repository is git-commit
. This is why he called commit
; You commit changes to the repository. git-add foo
adds foo
to the staging area, not to the repo itself.
Your git
repository has three โareasโ, working
, staging
and repository
, shown here (image taken from the Pro Git book ):
You make changes and work in the creatively named "working directory".
When you have made some changes, you want to prepare for committing. This is where the "setting zone" begins. You "stage" the changes you want to make, and when you are happy with how the commit will look, you transfer the "intermediate area" to the "repository". [Note: on the man
pages, this staging area
is mainly related to index
].
This allows you to be more flexible. You can make all the changes since the last commit, or you can create separate files, or you can create parts of the files. You can add and delete files from the staging area without losing changes or ruin the repository history. What the git add
and git rm
commands do; they are added from the working directory
in the staging area
, but they are not added directly to the repository
. (Hope the image helps make the differences clear).
Your steps are fine. If you want to know more about branching, committing, manipulating commits and branches and much more, I would recommend reading the Pro Git book - it got a whole bunch of beautiful pictures and language, simple enough so that I can understand it;)