Chances are high that the Git is already installed and configured on your computer (or the computer given to you). First two sections in this post confirm the installation and configuration. These two sections also walk you through installation and configuration if you have new computer.
Installation
You can confirm the Git installation by running following command in Terminal or Git Bash.
$ git --version
Note: Every command, here and in the future, starting with the character $ is typed into a Terminal or Git Bash. The character $ is not to be typed out because it represents the prompt.
If you get some version number as output, then that means Git is installed on your computer. If not then you need to install Git from its official download page. If you're Ubuntu user, run the following command in Terminal.
$ sudo apt-get install git
This will install Git on your computer and then you can again type the version command to confirm the installation.
Configuration
Once Git is installed on your computer, you need do some configuration in order to properly use Git. This includes setup the identity and add SSH key.
The identity is required. In this way, your name should display next to commit/changes you do in project. Again, chances are high that identity is already configured on your computer. You can check it by running following command in Terminal or Git Bash.
$ git config --global user.name
Kiran Chauhan
If identity is set on your computer, you'll see the name (such as "Kiran Chauhan" in my case) as output. If not then you can set the identity with your name using following command.
$ git config --global user.name "Kiran Chauhan"
This will set the name identity. You can confirm this setup by running following command.
$ git config --global user.name
Kiran Chauhan
The name identity is now set.
You also need to set email. First let's confirm if the email is set or not by running following command.
$ git config --global user.email
kiran@example.io
In case, if you don't get the email as output, you can set it using following command.
$ git config --global user.email "kiran@example.io"
This will set the email for you. You can confirm this setup by running following command.
$ git config --global user.email
kiran@example.io
SSH Key Configuration
You need SSH key to work with local instance of the project (and this is recommended way, if you ask us). Again, chances are high that SSH key is already generated on your computer (in this case, you can skip the generation step). You can confirm it by going to one of the following path.
-
Windows user -
C:/Users/YourUser/.ssh
folder - If this.ssh
folder exists, then key is already generated. -
Ubuntu user - Look for hidden
.ssh
folder in you$HOME
folder. If this.ssh
folder exists, then key is already generated.
If this folder is not exist at the mentioned location, that means you need to generate SSH key. Please follow these steps to generate SSH key.
- Open Git Bash or Terminal.
-
Paste this command by replacing with your email.
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
- This command will create new SSH key (You need to press 'Enter' couple of times) at the one of the above mentioned location.
Once SSH key is generated, you need to add this key to Git instance. Following are the steps you need to follow.
- Login with your account.
- Click on Profile.
- Choose SSH Keys.
- Click on Add New.
-
Paste the key from
.ssh/id_rsa.pub
(be sure about this) - Save with some name.
You are now ready to work with SSH Git URL. You can now clone the Git project with SSH URL.
Workflow
You'll always have the project in Git before you start your task (if
project is not there, don't work). with some default configuration and
few branches. These branches are development
,
RC
, and master
. If you're not seeing one of
these branches, ask admin to create first.
You'll have tasks in system (if not create one) with unique project task number. The task mainly divided into two parts - enhancements(feature) or bugfix (there are others but those are specific ones and you'll to confirm with your team for different category).
Following are the steps, you need to always follow while working with project task and until task completes and moved to production.
- Check if the assigned ticket is bug or enhancement. If assigned ticket is enhancement, mark it as feature and if assigned ticket is bug then mark it as bugfix.
-
Check out the
RC
branch and create a new branch with name in following pattern.-
If feature then - feature + / + project task # + at max
three words description separated by dash. e.g.
feature/5603-speed-problem
. -
If bugfix then - bugfix + / + project task # + at max three
words description separated by dash e.g.
bugfix/5707-send-mail-log
. - All characters used in branch name must be in lowercase.
-
If feature then - feature + / + project task # + at max
three words description separated by dash. e.g.
- By following step #3, you just created a local branch. This branch is local and you'll not see at Git instance, if you search for it online.
-
You need to register(push) the branch online via
push -> origin
. - You can now check out (or already checked in) the created branch and start working on it.
-
Once your changes are done, you need to commit your changes by
following these steps -
- Stage your changed files.
- Commit the changes by writing an appropriate commit message. Commit messages such as issues fixed or done are not acceptable.
- Push the changes to your branch.
-
Now, your changes are up and residing inside your branch (both locally
and online). You need to add or merge your branch in
development
so that you can test your changes indevelopment
server. -
To merge your changes into
development
, you need to check out thedevelopment
branch. -
After checkout the
development
branch, you can merge your branch intodevelopment
. This will move your changes intodevelopment
branch/server. -
In order to move the changes into
RC
branch, you need to create a pull request. This require a code review. So, the code review can be also done. -
After code review confirmed, you can merge your changes into
RC
from Git instance. -
Finally, your team leader or senior developer will move changes from
RC
tomaster
based on your project deployment cycle.
The process is straight forward but might looks difficult for couple of days because you might not used to be with it. Once you get familiar with it, you'll be happy Git user.
Useful Git GUI
- Sourcetree (for Windows and Mac)
- GitHub Desktop (for Windows and Mac). For Linux try this.
Labels: git