I read the documentation and googled a good bit, but there is no real simple steps to be able to commit your local changes to github. I compiled the following steps and I just want to make sure am doing the right thing. If I changed a file foo.java locally:
git status -s //will show me that foo.java has changed
git add foo.java //will add it to my local repo
git commit -m "my changes" //commit to the local repo
git tag "v1.1" //create a tag
git push --tags //finally, move the local commit to the remote repo with the new tag. this will prompt for your password. if no tag is set as in step 4, then just
git push
is enough. right?
I am just trying to make sure that these basic steps for the most use cases is what is required to use github. I am brand new to github, and these steps are working for me, but want to make sure i am not making any fundamental mistake. Please comment if there are any missing steps. Again, am concerned about the most generic day-to-day use (like, am not really concerned about branches, etc. which I will learn on a need basis). Thank you in advance.
This Git command lists: Files that are not tracked and in your working directory. Modified files that have not been updated to the branch. Staged files that are ready to be committed. Find commits easier by assigning a handle to a commit using the git tag command.
For example, the basic Git following command will index the temp.txt file: git commit will create a snapshot of the changes and save it to the git directory. Note that any committed changes won’t make their way to the remote repository. git config can be used to set user-specific configuration values like email, username, file format, and so on.
Hence, the add command should always precede the commit command. While you use the add command to point at the particular file you want to capture in its current state, you use the commit to save a copy of what you captured.
git branch: Git branch command is used to list down all the branches that are locally present in the repository. Git branch [branch-name]: This is used to create a new branch.
Your steps are fine. To nit-pick slightly, though, about the comments:
The comments about step (2) and (3) are not the best way to think about what's 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 which "adds" your file to the local repository is git-commit
. That's why it's 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
, depicted here (image taken from the Pro Git book):
You make changes and work in the creatively named "working directory".
When you've made some changes, you want to prepare to make a commit. This is where the "staging area" comes into play. You "stage" the changes that you want to commit, and when you're happy with what the commit will look like, you commit the "staging area" to the "repository". [Note: in the man
pages, this staging area
is mostly referred to the index
].
This allows you a lot of flexibility. You can stage all the changes since your last commit, or you can stage files individually, or you can stage parts of files. You can add and delete files from the staging area without losing changes or messing up the repositories history. That's what the git add
and git rm
commands do; they add from the working directory
to the staging area
, but they don't add directly into the repository
. (Hopefully the image helps make the distinctions clear).
Your steps are fine. If you want to understand more about branching, commiting, manipulating commits and branches and whatnot, I'd recommend reading the Pro Git book - it's got a whole bunch of pretty pictures and language simple enough that I can understand it ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With