Git, Magical Tool Used by Software Developers

Why this tool is important and is called magical things?

1. Clone a Repository

2. Develop and create changes for yourself

  • Create new branch git branch <branch name>
  • Checkout to available branch git checkout <branch name>
  • Create new branch and checkout to that branch
    git checkout -b <branch name>
  • Delete branch from repository git branch -d <branch name>
  1. You create new branch called feature/paymentfrom main branch and checkout to that branch using git checkout -b feature/payment
  2. Your teammate also create new branch called feature/refund from main branch and checkout to that branch using git checkout -b feature/refund.
  3. Both of you can develop your feature in your own separated branch without breaking each other works.
  4. Both of you push your changes to each branch and you won’t bother to sync with each other changes or pull first before push.

3. Pull changes from remote repository

  1. You create new branch called test/payment-and-refund from your current branch feature/payment using git checout -b test/payment-and-refund
  2. You pull changes from your teammate’s branch’s named feature/refund using git pull origin feature/refund
  3. Finally, you have your teammate’s changes in another separated branch just dedicatedly for testing.
  4. And you can get back to your branch using git checkout <branch name>

4. Merge branch with merge request

Merge Request example in GitLab. You see that the merge request needs 1 approval in order for it can be merged to the main branch.
Example of commenting with suggestion of changes.

5. Solve merge conflict

Example of conflict caution in merge request Gitlab.

a. Use resolve conflict GUI from the platform

Fix conflict using Interactive Mode.
Fix conflict using Edit Inline.

b. Resolve conflict locally (using VSCode)

6. Git Rebase

Illustration of git rebase.
# Commands (from git rebase manual):
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
  • pick (p): choose this commit as is
  • drop(d): delete this commit
  • squash(s): merges the changes of this commit with the commits that follow.
8d96339 fix sonar issue and refactor error handler
bce3eed fix linter
283b8ad change black gitlab ci
7490fa4 fix type(T) bug vurnerability
c2c3793 change gitlabci for pytest
c694a1f fix gitlab ci sonarqube in dev branch
96e2ef7 fix sonarqube ci error
3e38e04 fix linter

Caution

7. Git Workflow

Branch development illustration, taken from Kofax

Finale

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store