Eventdone Git management
Basic Instructions:
There are three types of files in git:
1. Untracked (git doesn’t know about these files, each new file is an untracked file initially)
2. Unstaged (tracked but has some changes)
3. Staged (unstaged file added to staged, these files are committed when you make a new
commit)
Basic git commands:
- Clone the project (at very start)
git clone <repo url>
- Taking pull of a remote branch
git pull origin <branch-name> e.g. git pull origin master
- Creating a new branch
git branch <branch-name> e.g. git branch first-branch
- Checking out to a branch
git checkout <branch-name> e.g. git checkout first-branch
- Deleting a branch
git branch -D <branch-name> e.g. git branch -D first-branch
Hints:
- When writing a branch name, write its initial word(s) and press tab button and the branch
name will complete automatically.
Working on a new feature:
When you are going to start working on any new feature. You need to follow the following
steps. For example, you need to work on the ibox.
Create a new branch:
The git command for this is:
git branch <branch-name>
e.g. git branch ibox-new-design
If we can have a unique number for each feature, like a card number or excel sheet row number
(if that wouldn’t change in future). We can use that number with the branch name, e.g number
associated with ibox feature is 364, we can make the branch name like this
git branch 364-ibox-new-design
(It’s a normal convention mostly used in different projects. Its benefit is that you don’t need to
remember the branch name for future use, just remember the branch number which you can
also see from the sheet or card. )
Next Step:
At the end of each day commit your code to your branch. And push it to the origin. (optional)
Steps to commit:
Add the required files using
git add . or git add <file-name>
git commit -m ‘commit message’ (write a commit message according to your need)
git push origin <branch-name>
Rebasing:
Work on that branch. After each 2-3 days period, rebase that branch with master branch.
Steps to Rebase:
git status
git stash (do this only if git status shows any files)
git checkout master
git pull origin master
git checkout <branch-name>
git rebase master
If this command executes successfully, you are good to go. But if it shows conflicts in an of the
files, first resolve those commits and then move ahead.
Resolve Conflicts:
git status (will show the files with conflicts in red, go to those files and resolve the
conflicts manually)
git rebase –continue
You may have to repeat the above two steps, if conflicts rises again.
git stash apply (If you previously executed git stash command)
If git stash apply, shows conflicts, resolve those conflicts.
When Done:
When the working on that branch is completed and it’s the time to merge the branch into
master branch. Follow the following steps:
- Rebase the branch with master branch (steps mentioned above)
- Merge the current branch into master branch (Steps to merge listed below)
- Push the master branch to the origin
- Delete that branch from your local (optional)
- Delete that particular branch from the DevOps
Merge Steps:
git checkout master
git merge <branch-name>
git commit -m ‘this is a merge commit’ (write your custome message)
Note: The procedure is devised for initial experience, we can improve and modify it, depending
on its success and the issues faced.