Understanding GIT and GITHUB

narendrapalacharla
3 min readJan 26, 2021

Git is an decentralised version control tool which helps the developers to collaborate , share the projects and adapt easily.

HOW TO INSTALL GIT

Step 1 — Update Default Packages

logon to your ubuntu 20.02, open your terminal.

$ sudo apt update

Step 2 — Install Git

$ sudo apt install git

Step 3 — Confirm Git Installation

$ git — version

output: git version 2.17.1

Step 4 — Set Up Git

$ git config — global user.name “Your Name”

$ git config — global user.email “youremail@domain.com”

COMMIT THE FILES TO GIT AND PUSH REPO’S ON GITHUB

Step 1 — Create a directory named “first commit” in-home(cd ~)

Step2 — Create a file named “file.txt” using the touch command

Step3 — Initialise the Git repo in the “first command ” directory

Step4 — Stage the file using “git add file.txt” and track the status of the file1.txt

Step5 — Commit the file to Git

Step6 — Create a repo in github.com and add local remote origin

if you Push the files to Github Repository (you will encounter an error)

the error will be like git error: failed to push some refs to remote

few may suggest the force push the changes to remote, NEVER! NEVER! do that may remove the files from the remote.

step7 — Pull the changes first from remote/master to your local machine.

step8 — Push the changes to remote/master

happy commit-ing !!

GIT WORKFLOW in layman’s language

source of the image

I am doing this scenario to make you understand things better, I used to confuse about this git command’s workflow. this can be easily memorized 👇

  1. If you find a Girl/Boy’s profile on FB, if she/he is interesting, you add him/her to your friend's list, Right?🙂
  2. If you guys build rapport with each other, you commit to a relationship.👩‍❤️‍👨
  3. Once you are in a relation, you guys exchange gifts (pull and push) 🎁

relate the both

git add → adding a friend(girl/boy) in a social media

git commit →commit into a relationship

git status(show’s committed files to git) →check your relationship status(it show’s committed)

git push →it is more like sending gifts

git pull → receiving gifts.

this is made for a basic understanding of the workflow of GIT.

BRANCHING AND MERGING

branching makes life easier in software development, we can create multiple branches and can work on different features and bug-fixes, developers can work on their own branches.

once the developers want to merge their code, they will pull-request the changes to the master/main branch, by assigning it to a reviewer in the team, so they will review the code and resolve if there are any merge conflicts before merging. merge conflicts occur if two developers work on the same lines of the same file. merging will be happening in two ways

  1. Fast-forward merging
  2. 3-way merging

Fast-forward merging will happen if the commits have the direct path, in this master will head to the recent commit.

3-way merging is a bit different, where the commit’s are having diverged paths,

it takes the three commits into consideration

a. base commit where the branches have diverged,

b, c . last commit of the individual branches

then it will create a new commit.

few more commands which may help, while playing with branches

git branch <branch name> — create a new branch

git checkout <branch name> — switches to the specific branch

git branch -d <branch name> — Deletes the given branch

git checkout -b <branch name> — Creates and switches to the new branch

git commit -am “message” — adding to staging area + committing stage at one shot

--

--