This article is about some of the good practices I learnt from the industry when using the GIT..
Lets briefly see what is GIT. It is a distributed version controlling system. You can find a wikipedia article from here. In simple words when you are developing a system, you might need to keep track of the changes/modifications you did to the code and once in a while you might need to revert to a previous working state of a code. GIT is a handy tool for that task.
You might be developing a system as a project where each members contribute to the code, So how can you support this? GIT is the solution, you can have you code in a GIT repository and you all can work on the same code without interfering to others (given that you use GIT effectively).
Hope you got enough motivation ;)
I will explain basics of the GIT in a later article.
In this article I'll introduce you GIT best practices
Hack 1 : Every day before you start your work take a pull from the repository
git pull origin
This will make sure your code is up to date
Hack 2 : Every day before you finish you page push all your changes to the repository
this has few steps let me explain them to you in below
This will make sure the code in the repository contains all the up to date modifications

Hack 3 : Use separate branches to implement separate features/ functionalities
git branch branchName
git checkout branchName
Use a meaningful for every branch, so that your life would be easy, with separate branches you have a lot of flexibility to even to hold current work and start implementing another feature on another branch.
Hack 4 : Never work on the 'master' branch
git checkout branchName
If you work on the master branch you are in a big trouble when pulling the changes. If you code got broken due to the pull, it wouldn't be easy to solve the conflicts and merge the changes.
Hack 5 : Steps to push changes
Here I assume you are in a branch called my branch.
git add --all <-- stage all the modified/created files
git commit -m "commit message"
git checkout master <-- go to the master branch, note none of you new changes are
visible in the master branch
git pull origin <-- pull and get the up to date code from the repo
If conflicts are there, resolve them and merge the code. Now you have up to date code in the
master branch
git checkout myBranch <-- go to myBranch
git rebase master <-- take the changes in the master to myBracnch
If conflicts are present
git mergetool <-- using the mergetool to resolve confilcts
git commit -m "message" <-- commit the changes in resolving the confilcts
git rebase --continue <-- command to continue the rebase process
git checkout master <-- go to master branch
git pull origin <-- check whether the code in the repository has been changed while we were working on the rebase process of myBranch, if the code is up to date we can continue the process, if any changes have been pulled, we need to again do the rebase process.
git merge myBranch <-- merge the changes of the myBranch to master
git push origin master <-- push the code to the repository, now the repository has
your code
Hack 6 : Add meaning full comments to commits
git commit -m "commit message"
Adding meaning full commit messages will make your life so easy when you want go back to a previous state. It is advised to use the commit message in present tense.
Here is a nice Git Guide
Ok those are the things I wanted to share, happy coding folks :D

You might be developing a system as a project where each members contribute to the code, So how can you support this? GIT is the solution, you can have you code in a GIT repository and you all can work on the same code without interfering to others (given that you use GIT effectively).
Hope you got enough motivation ;)
I will explain basics of the GIT in a later article.
In this article I'll introduce you GIT best practices
Hack 1 : Every day before you start your work take a pull from the repository
git pull origin
This will make sure your code is up to date
Hack 2 : Every day before you finish you page push all your changes to the repository
this has few steps let me explain them to you in below
This will make sure the code in the repository contains all the up to date modifications

Hack 3 : Use separate branches to implement separate features/ functionalities
git branch branchName
git checkout branchName
Use a meaningful for every branch, so that your life would be easy, with separate branches you have a lot of flexibility to even to hold current work and start implementing another feature on another branch.
Hack 4 : Never work on the 'master' branch
git checkout branchName
If you work on the master branch you are in a big trouble when pulling the changes. If you code got broken due to the pull, it wouldn't be easy to solve the conflicts and merge the changes.
Hack 5 : Steps to push changes
Here I assume you are in a branch called my branch.
git add --all <-- stage all the modified/created files
git commit -m "commit message"
git checkout master <-- go to the master branch, note none of you new changes are
visible in the master branch
git pull origin <-- pull and get the up to date code from the repo
If conflicts are there, resolve them and merge the code. Now you have up to date code in the
master branch
git checkout myBranch <-- go to myBranch
git rebase master <-- take the changes in the master to myBracnch
If conflicts are present
git mergetool <-- using the mergetool to resolve confilcts
git commit -m "message" <-- commit the changes in resolving the confilcts
git rebase --continue <-- command to continue the rebase process
git checkout master <-- go to master branch
git pull origin <-- check whether the code in the repository has been changed while we were working on the rebase process of myBranch, if the code is up to date we can continue the process, if any changes have been pulled, we need to again do the rebase process.
git merge myBranch <-- merge the changes of the myBranch to master
git push origin master <-- push the code to the repository, now the repository has
your code
Hack 6 : Add meaning full comments to commits
git commit -m "commit message"
Adding meaning full commit messages will make your life so easy when you want go back to a previous state. It is advised to use the commit message in present tense.
Here is a nice Git Guide
Ok those are the things I wanted to share, happy coding folks :D
No comments:
Post a Comment