How does it work?
GIT is a version control system, works completely based on local repository concept. It’s completely different than any other source version control systems like Perforce (I was using this before we migrate to git). It will maintain local repository and central repository and whatever your changes you make to your files will be added to staging Area.
When you commit your changes it actually records in a local repository as a snapshot and when you push your changes it will be merged with a central repository. Will use fetch concept to get the remote changes to your local repository.
Here you will find a list of GIT commands I generally use it during my development every day. Hope this will help you guys.
1. Creating a new branch
Ø git branch [new branch name]
Ex: > git branch mylocalJavabranch
2. Checking existing branches in your local repository.
Ø git branch
o/p:
myLocalJavabranch
javabranch
Customer-fixes
It will list down all your branches reside in your local repository.
3. Checkout to the branch
Ø Git checkout [your branch name]
Ex: git checkout customer-fixes
If you are working with multiple branches. May be you could have created different branches for different features which you have been working with.
4. Checking the status in your branch- It will show the added files and untracked files.
Ø Git status
5. Add unstaged files.
Ø Git add –all
6. Commit all your added and modified files to a local repository.
Ø Git commit –a -m “description about your commit”
7. Fetching from a central repository. It will bring all the modified files from a central repository to local repository.
Ø Git fetch
8. It’s always a good idea to fetch and rebase before you push your changes. This will bring all files from repository to your local branch and rebase your local changes on top of it.
Ø Git rebase [your remote branch]
Ex: git rebase origin/java
If any conflicts it will try to auto merge the files. If not, user has to merge manually and add that file to staging area so that it will be available for the next commit.
Due to conflicts, if rebase could not continue, use the following command to continue the rebase.
Ø Git rebase –continue
9. Push your changes to a central repository.
Ø Git push gerrit HEAD:refs/for/java
10. Checking the log history. It will list down all the local commits.
Ø Git reflog show
Every commit will generate a hash id to uniquely identify the commit. To check what you have submitted in that commit use this command.
Ø Git reflog [hash id]