#11 Task Advance Git & GitHub for DevOps Engineers Part-4

#11 Task Advance Git & GitHub for DevOps Engineers Part-4

What is Git Stash?

Git stash is like temporary storage where we can keep our work for a temporary purpose. suppose we are working on one project and suddenly we have an urgent requirement to add a new feature to another project. so instead of creating another branch, we can keep our current work in the stash and later on once the urgent work is finished we can get back our work from the stash.

Below are the git stash commands:

  • To stash an item.

    git stash

  • To view the stash list.

    git stash list

  • To get back stash work.

    git stash apply stash@{0}

  • To delete stash work

    git stash clear

What is Cherry-pick?

git cherry-pick command is used to pick a specific commit from one branch to another. suppose I am in the Master / Main branch and I want a specific commit from the dev branch then we can use git cherry-pick. Go Master / Main and type the below command:

git cherry-pick <commit id>

How to resolve merge Conflicts?

Git conflicts arise when two separate branches have made edits to the same line in a file or when a file has been deleted in one branch but edited in the other.

We can resolve merge conflicts issues by comparing all the changes and having a meeting with the dev team then, removing unwanted code and resolving them manually.

Task-01

  • Create a new branch and make some changes to it.

    We will create new branch dev

        git checkout -b dev
    

  • Make some changes to the new branch, such as adding or modifying code files.

  • Use git stash to save the changes without committing them.

  •    git stash save "Latest changes done"
    
  • Switch to a different branch, make some changes and commit them.

parim@DESKTOP-F85NG1F MINGW64 ~/day11/Devops (main)
$ git add.
parim@DESKTOP-F85NG1F MINGW64 ~/day11/Devops (main)
$ git commit -m "latest commit 1"
  • Use git stash pop to bring the changes back and apply them on top of the new commits.
parim@DESKTOP-F85NG1F MINGW64 ~/day11/Devops (main)
$  git stash pop

Task-02

  • In version01.txt of the development, the branch adds the below lines after “This is the bug fix in development branch” that you added in Day10 and reverted to this commit.

    Open the file vi version01.txt and add this line “This is the bug fix in the development branch”

  • Line2>> After bug fixing, this is the new feature with minor alterations”

    Commit this with the message “ Added feature2.1 in development branch

      parim@DESKTOP-F85NG1F MINGW64 ~/day11/Devops (main)
      $ git commit -m "Added feature2.1 in development branch"
      [main 44f2044] Added feature2.1 in development branch
    
  • Line3>> This is the advancement of the previous feature

    Commit this with the message “ Added feature2.2 in development branch”

  • Line4>> Feature 2 is completed and ready for release

    Commit this with the message “ Feature2 completed”

      Feature 2 is completed and ready for release
    
      parim@DESKTOP-F85NG1F MINGW64 ~/day11/Devops (main)
      $ git add .
    
      parim@DESKTOP-F85NG1F MINGW64 ~/day11/Devops (main)
      $ git commit -m "Feature2 completed"
    
  • All these commits messages should be reflected in the Production branch too which will come out from the Master branch (Hint: try rebase).

      git checkout master
      git branch production
      git merge --no-ff development
    
  • Rebase the commits in the production branch with the commits in the development branch using the following command:

    git rebase dev

  • git push origin prod

Task-03

  • In the Production branch Cherry pick Commit “Added feature2.2 in development branch” and added the below lines in it:

    git cherry-pick <commit id>

  • The line to be added after Line 3>> This is the advancement of the previous feature.

    vi version01.txt and add this line "This is the advancement of the previous feature."

  • Line 4>>Added a few more changes to make it more optimized.

    vi version01.txt and add this line "Added a few more changes to make it more optimized"

  • Commit: Optimized the feature

    git add .

    git commit -m "Optimized the feature"

    Thank You for reading this blog

    Parimal Pradhan

    You can follow me on LinkedIn for my daily updates:- linkedin.com/in/parimal-pradhan-b62021168

    Great initiative by the #trainwithshubham community. Thank you Shubham Londhe

Did you find this article valuable?

Support Parimal Pradhan by becoming a sponsor. Any amount is appreciated!