Skip to main content

Command Palette

Search for a command to run...

🚀 Day 11:Advance Git & GitHub for DevOps Engineers: Part-2

Updated
3 min read
🚀 Day 11:Advance Git & GitHub for DevOps Engineers: Part-2
T

As a DevOps Engineer, I'm passionate about building and maintaining robust, efficient, and scalable infrastructure to enable seamless software delivery. With a strong foundation in C/C++, Linux, and a toolkit that spans AWS, Jenkins, Docker, Nagios, Kubernetes, YAML, Ansible, Terraform, Bash Scripting, Git, and GitHub, I'm well-equipped to tackle the challenges of modern software development and deployment.

This article covers essential Git commands and concepts, focusing on Git stash, git cherry-pick, and conflict resolution. Git stash allows temporary saving of changes without immediate commitment, useful for context switching. Git cherry-pick selectively applies commits from one branch to another. Conflict resolution is discussed, emphasizing the use of commands like git status, git diff, and git add. Three tasks are outlined, including creating, stashing, and applying changes across branches, reflecting commit messages in different branches, and cherry-picking specific commits with additional changes for optimization in a production branch.

Git Stash:

In Git, git stash is a command that allows you to temporarily save changes that you don't want to commit immediately. It's particularly useful when you're in the middle of working on something, and you need to switch to another branch or deal with a different task without committing your current changes.

Cherry-pick:

Git cherry-pick is a command that allows you to select specific commits from one branch and apply them to another. This can be useful when you want to selectively apply changes that were made in one branch to another.

To use git cherry-pick, you first create two new branches and make some commits to them. Then you use git cherry-pick <commit id> command to select the specific commits from one branch and apply them to the other.

Resolving Conflicts:

Conflicts can occur when you merge or rebase branches that have diverged, and you need to manually resolve the conflicts before git can proceed with the merge/rebase. git status command shows the files that have conflicts, git diff command shows the difference between the conflicting versions and git add command is used to add the resolved files.

Task-01

Certainly! Let's break down the task into steps:

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

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

  • Switch to a different branch, make some changes and commit them.

  • Use git stash pop to bring the changes back and apply them on top of the new commits.

Note:

  • If there are conflicts during the git stash pop operation, Git will pause, and you'll need to resolve the conflicts before continuing with git stash pop --continue.

Task-02

Certainly! Let's break down the task into steps:

  • In version01.txt of dev branch add below lines after “This is the bug fix in dev branch”

  • Added feature2.1 in dev branch

  • Line3>> This is the advancement of previous feature

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

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

    Commit this with message “ Feature2 completed”

  • All these commit messages should be reflected in Production branch too which will come out from Master branch (Hint: try rebase).

Task-03

Certainly! Let's break down the task into steps:

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

    git checkout production

    git log

    git cherry-pick <commit-id>

  • Line to be added after Line3>> This is the advancement of previous feature

  • Line4>>Added few more changes to make it more optimized.

    vim version1.txt

    git add version1.txt

    git commit -m "optimized the feature"

Now, the changes from the "Added feature2.2 in development branch" commit have been cherry-picked into the production branch, and new lines have been added with the commit message "Optimized the feature."

More from this blog

Trushid's blog

90 posts

Proficient in DevOps, Cloud & SDLC including analysis, design. Scripting, testing, automation, version control, documentation and support