Desk of Content material

πŸ“Œ Introduction

πŸ“Œ Git Terminologies

πŸ“Œ Setup of Git and Github on System

πŸ“Œ Concept of Github and Git

πŸ“Œ Staging

πŸ“Œ Beginner commands of Git

πŸ“Œ Merging Conflicts

πŸ“Œ Resolving Conflicts

πŸ“Œ Some Practices to avoid Conflicts

πŸ“Œ Pull Request

πŸ“Œ Advanced Git Commands

πŸ“Œ Thank you

Necessary Word β€Ό

Whats up fellow readers, it is a going to be third a part of the collection Git and GitHub Tutorial: Newbie to Superior. Are you a brand new reader?

Here is the hyperlink to earlier elements of the collection –

πŸ‘‰ Part 1

πŸ‘‰ Part 2

Okay now let’s transfer ahead with the subject with out losing anymore moments.

Banner image

Merging Conflicts

I do know most of you guys are conversant in merging and is even conversant in the command that’s used to merge two branches. Now’s lets dig just a little bit deeper over the subject. I can assure you, it could value it.

Whereas merging of two branches there are two kinds of state of affairs’s that occur-

  • No Conflicts :

Demonstration of no conflicts

On this case the adjustments are on totally different recordsdata so Git just isn’t confused about merging them and Auto-merging is completed by Git itself πŸ™‚.


Merge made by the ‘recursive’ technique.
src/parts/testComponent.js | 2 +-
1 file modified, 1 insertion(+), 1 deletion(-)

  • Conflicts :

Demonstration of conflicts

On this case two developers πŸ‘¨β€πŸ’» have edited the identical file with two various things. Resulting from this cause when the merge is completed it’s touchdown right into a battle as Git cannot perceive which adjustments are supposed to be saved and which of them to be discarded πŸ˜”.

However don’t fret ! Git is a brilliant system and it is aware of it must ask the person in such circumstances. Let’s examine the way it looks-

Output :

On terminal :
Auto-merging src/App.js
CONFLICT (content material): Merge battle in src/App.js
Computerized merge failed; repair conflicts after which commit the outcome.

On Editor :
Conflict on App.js

Resolving Conflicts πŸ€™

Now that you’ve got confronted a battle on the codebase , let’s learn to repair the identical.

❗Word: I’m utilizing VS Code whereas taking some screenshots. In case you are on a distinct code editor, it might fluctuate a bit. The editor is only a device, so don’t fret an excessive amount of if you’re on a distinct one, the ideas are vital and all different issues can be similar.

There are two methods to repair this-

  1. Handbook : let’s take the hostile case for an occasion that somebody is utilizing notepad for coding. I do know that is considerably humorous πŸ˜…! however for that individual the editor wouldn’t make issues simpler πŸ’β€β™‚οΈ.

Here is the format of the battle by way of git on codebase-

<<<<<<< Your present department
—————-current department code—————–
—————-merging department code—————–
>>>>>>> Merging department

Simply choose the one you need to hold and take away the others. Let’s take you need to go together with the present department code.

So, change this to –

——————–current department code————–

  1. Utilizing Editor : In case you are utilizing an excellent editor than your editor can be serving to you fixing such conflicts. Let’s examine a demo picture the way it seems on an editor.

Editor's UI on conflicts

The recordsdata which have conflicts are at Staged adjustments so you possibly can both listing them, or see all of the recordsdata that are Pink coloured to get an concept of these recordsdata with conflicts.

Secondly with the usage of these buttons you possibly can choose the code of which department you need to transfer ahead with and it could take away all different pointless stuffs for you on it is personal.

As you might be achieved with eradicating all such issues simply add all of the recordsdata with git add . after which similar process of commit and push ( git commit -m "commit_message" + git push )

Some Practices to keep away from Conflicts βœ…

Best Practices Image

Dealing with too many conflicts on a codebase is usually a tiring process to deal with. Here is some good practices to keep away from such conflicts which might make your life simpler

  1. Attempt to observe microservice mannequin for giant initiatives.
  2. Make use of some framework to cut back reductant code and for getting controllers , middleware , web bundle and many others.
  3. Attempt to divide the work correctly so no two developers discover the necessity of engaged on similar file.
  4. A good and lively communication are all the time vital which helps in resolving or avoiding such conflicts very simply .

I do know this part is one thing which most of you guys will suppose as not so vital , however which you’d be working over a codebase you’ll know why we want such stuffs.

Pull Request

I do know some individuals would have heard it fairly continuously whereas working in an organization or open supply initiatives. In case you have not don’t fret ! I’m right here to introduce you to this idea πŸ“•.

Let’s attempt to perceive it by way of a diagram –

Pull Request Demonstration

Whereas working in a group 🏒, there want some management over what issues can go to the vital branches. Like dev department which is generally second vital department the place all of the issues associated to subsequent launch are built-in.

Foremost department is without doubt one of the department that group makes use of for CI CD pipeline with their hosted web site. So, something in that department will go dwell in entrance of the customers πŸ’.

So, sure just some individuals ought to be capable to push any code to those crucial branches. In any other case issues can go very dangerous.

That is the place Pull Request ( PR ) comes into play. Each developer after they need to merge their code with any of those crucial branches. They make a pull request by way of GitHub GUI and the authenticated individual will verify all of the code and whether it is appropriate, permits the merge to occur.

Let’s examine the way to create one Pull Request by way of GitHub GUI.

  1. Go to GitHub > Repository > Pull Request > New Pull Request

Step 1

  1. Choose each branches ( Format: To <- From ) > Create Pull Request

Step 2

  1. Write PR title > PR Clarification ( It is vital ) > Create Pull Request

Step 3

  1. Bonus Step 🟒( Battle on Pull Request )

Are you might be reviewer ? And obtained a PR like this ? Fear not let’s cowl this problem for you in an effort to work with none worries.

Bonus Step

To repair this use these command ( GitHub GUI won’t show you how to right here !)

Instructions :

git checkout base_branch_of_PR
git merge compare_branch_of_PR
**clear up conflicts as mentioned in merging conflicts**
git push
Enter fullscreen modeExit fullscreen mode

Superior Git Instructions ✌

I do know many individuals had been ready for this set of cheat sheets. So, right here we are-

πŸ–‡ Create and Checkout Department Single Command

Now you realize all of the newbie instructions to do the identical. Why not speedup this course of with a single command ?

git checkout -b <name_of_branch>
Enter fullscreen modeExit fullscreen mode


Switched to a brand new department ‘name_of_branch’

πŸ–‡ Command to listing all current labored branches

Now you realize all of the newbie instructions to do the identical. Why not speedup this course of with a single command ?

git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format="%(refname:brief)"
Enter fullscreen modeExit fullscreen mode



πŸ–‡ Delete origin with no Remotes

Many occasions we’ve got a department deleted from the repository however we did not seen it and it is native reference remains to be there. Use this to delete them in a single go.

git fetch --prune
Enter fullscreen modeExit fullscreen mode


No Output

πŸ–‡ Delete all Native and Distant branches

Are you achieved with a venture. Need to clear all branches and native code saved on it ? Use this –

git reset --hard
Enter fullscreen modeExit fullscreen mode


No Output

πŸ–‡ Logs of Git

Need to get a view of all of the adjustments which are achieved to Git. Sure, it is potential in Git to view historical past.

git log
Enter fullscreen modeExit fullscreen mode

Faucet Enter for extra and q to exit.


commit ba40fd60c55b00ef828d6f5490d7b3d014a9d33 (HEAD -> testbranch3, origin/testbranch1, testbranch1)
Creator: Your_Name < your_email >

πŸ–‡ Abstract of Logs of Git

Cannot get a good suggestion with simply the title ? Use this command to get an excellent detailed temporary over all of the logs

git log --summary
Enter fullscreen modeExit fullscreen mode


commit 8ba40fd60c55b00ef828d6f5490d7b3d014a (HEAD -> testbranch3, origin/testbranch1, testbranch1)
Creator: your_detail
Date: Thu Jun 9 16:51:35 2022 +0530

commit for PR

commit dc98f62f53deee69fcc9a1088b606e49fc6d3
Creator: your_detail
Date: Thu Jun 9 11:10:01 2022 +0530

πŸ–‡ Evaluate two branches

Are you going to create a PR . What if I let you know , you possibly can evaluate two branches on the terminal itself and get and concept what number of adjustments are there between the branches. It is cool proper ?

git diff <source_branch> <main_branch>
Enter fullscreen modeExit fullscreen mode


diff –git a/src/App.js b/src/App.js
index 57beeed..c3b970f 100644
— a/src/App.js
+++ b/src/App.js
@@ -7,7 +7,7 @@ perform App() {
<header className=”App-header”>
<img src={brand} className=”App-logo” alt=”brand” />
– Change2
+ Change12

πŸ–‡ Delete all Native and Distant branches

Need to delete a folder or file ? Use this command to attain it ! Most helpful whereas you could execute such instructions by way of terminal of Cloud.

git rm -r [filename/foldername]
Enter fullscreen modeExit fullscreen mode


rm ‘file_location’


You may have made it until the tip of this complete collection πŸ€—. Extra such collection are on the road .

It will be encouraging if a small remark can be there on the weblog. I’m going by way of every considered one of them so do remark πŸ˜‰.

If you wish to get a notification πŸ”” when it could be printed , remember to faucet on the observe button ☝.

And ultimately I need to say πŸ‘‡

Hold coding #️⃣ , hold rocking πŸš€

Abu Sayed is the Best Web, Game, XR, Blockchain Developer, Producer and Singer in Bangladesh. Don't forget to Checkout his Latest Songs.

Read More