git-workflow

 //////////////////////

https://linuxdady.com/git-workflow-for-beginners/

https://linuxdady.com/what-is-stash-in-git/

/////////////////////////

Git workflow for Developers and DevOps Engineers

In earlier tutorials we have already discussed before learning any devops tools we should learn behavior of that tools. Means how that tool will work and what will be architecture and workflow of that tool. So, we will discuss today about git workflow

Git workflow

Git workflow is the combination of steps that we have to follow before starting development cycle means how developers pull, push, commit, clone and mange their code on git server. Here we will take real time scenario.

Suppose our company got a project and hire two developer Harry and Joy for coding. Both of developer will work according to below diagram. First Harry will start development cycle. Go throw once from below diagram for better understanding.

git workflow

As shown in figure first day Harry will come and make a directory. After that Harry will start development cycle.

When directory will created Harry will convert this directory into git format with git init command and after that will start coding.

git workflow - LinuxDady

[Click & Read:–  What is git and basic terminology for DevOps engineers]

[Click & Read:–  Kubernetes rolling update strategy for beginners]

After making directory into git format Harry will write their code. Suppose Harry start their code from hello word like below command. Then Harry will add readme file into git staging state.

Harry file has been added into staging area now Harry can commit this file. Note that if Harry file is in non staging area than he cannot commit. First he have to add his code into staging state. Then he will be able to commit. 

Git workflow -1- LinuxDady

After commit anyone can check commit log and changes in code by below commands.

git log --Linuxdady

Git origin

Git remote origin command is used to save address of remote repository locally or we can say on developers machine. After doing this there will be no need to add master repo URL every time. After git origin command use git push command that will push Harry code into remote repository on git centralized server.

git push --LinuxDady

Now origin has been added. In your case change remote repo url accordingly. After that run below command and give user name and password. 

Now go to your GitHub/GitLab/Bitbucket dashboard and check data into your repository. Data should be there. 

git workflow -3-Linuxdady

Next day Joy will come and first he will clone repository from central git server. No need to perform basic step that was performed by Harry.

We can also use ssh url instead of https url. But first we have to add ssh key on GitHub/GitLabs/Bitbucket etc. 

clone repo

For next developers development cycle will remain same. New developer will come and before starting coding first he will have to clone repository from centralized git server with latest changes of other developers.

All about git workflow

We have discussed git workflow in this tutorial  because before moving next it is must. So understand it very carefully. Still if anyone have query write me in comment box. I will try my best to resolve that.

Interview question related to git workflow

  • How to enable versioning on a directory.
  • Explain git workflow.
  • What is git origin?
  • Can we add multiple origin at time?
  • How to delete versioning from any directory?
  • What is difference between git pull and git clone. Please answer this question specially in comment box because this is interviewer favor question in git.
  • What are the difference between a directory and repository?

///////////////////////////

What is stash in git and its use case for beginners

Today we are going to learn what is stash in git and what are the role of git stash in developer’s daily routine life. Why developers should use git stash instead of git new branch and what are the advantages of using stash area.

what is stash in git?

For better understanding what is stash in git suppose you are a developer. You came in office and start coding. From last 2-3 hours you are working on your code. But your task is not completed yet means still you are continuously working on your code.

Means while time you got a ticket and your manager says Harry do it first on high priority because this is production issue. Now in this situation Harry have two option. He can discard his changes from code. But he can’t do it because he is working on it from last 2-3 hours.

Second option is he can commit his code into branch, but his task is not competed yet, still he is working on it when he got the ticket. But harry compulsion is he have to work on production ticket first on high priority. But if he will switch from his current branch to another branch and commit anything into that branch his all previous branch changes will lost.

So, to resolve this issue Harry needs an alternate and that alternate is git stash. By using this we can save our incomplete task into stash area and can work parallelly on another issue. 

Demo of stash area

Let have a demo we will write some code for demo purpose after that we will save and roll back that code from stashing area. Let’s do it.

What is stash in git

suppose we have written some code into this file according to our requirement. Mean while we got a ticket regarding production issue. My code is pending so I cannot commit it. So, let’s save our task into stash area. So, first check status of our code

When we will check git status it is showing M means modified not committed yet. But when we check git status after saving code into stash area then it is showing repository in clean state.

what is stash in git - Linuxdady

Now we can switch to any branch and can work on open issue because our changes has been saved into stash area.

[Click & Read:–  What is git and basic terminology for DevOps engineers]

[Click & Read:–  Explain git workflow for beginners step by step]

[Click & Read:–  How to add ssh key on GitHub step by step]

Roll back changes from stash area

Now suppose after saving our code into stash area we have worked on bugs that was open in production and fixed that bugs now switch to branch in which we were working and roll back our 2-3 hours work from stash area. In my case stage is the developers branch name where developer were working change accordingly.

switch git branch

what is git stash -- Linuxdady

Our pending task has been rolled out from stashing area. Now we can work as before. Now I think you have understood very well about what is stash in git. But Now my question is why we should use stash area instead of branch.

We are using git stash because this is just a convenience way. Since branches are so easy to manage in git, I personally almost prefer creating a new temporary branch than stashing, but it’s depend on choice mostly. There is no compulsion you have to use git stash only. Go ahead according to situation and taste means we can use anyone from stash area or git branch its depend on our choice.

Biggest advantage of git stash area 

One important advantage of using  stash area is, we can keep our commit history clean by avoiding unnecessary commits just for the sake of switching from one branch to another.

Conclusion and all about what is stash in git?

In this tutorial we have discussed what is stash in git and it’s use cases in a developer life. But still anyone have query write me in comment box. I will try my best to resolve that query. Kindly keep answering below interview question in comment box. These questions will help a lot of those engineers which are doing preparation for interview. Also, you can add interview question if you have faced ever.

Interview question related to stash area

  1. What is the difference between git stash and git staging?
  2. Why we are preferring stash area instead of new branch?
  3. How to roll back our pending task from stash area?
  4. What is meaning of clean state and how we will check repository status?

/////////////////////////////


//////////////////////////////

Comments