Skip to main content

Command Palette

Search for a command to run...

Advance Git & GitHub for DevOps Engineers: Part-2

Published
3 min read
Advance Git & GitHub for DevOps Engineers: Part-2

Git Stash:-

git stash temporarily shelves (or stashes) changes you've made to your working copy so you can work on something else, and then come back and re-apply them later on. Stashing is handy if you need to quickly switch context and work on something else, but you're mid-way through a code change and aren't quite ready to commit.

The git stash command takes your uncommitted changes (both staged and unstaged), saves them away for later use, and then reverts them from your working copy.

Command:

git stash or git stash -u

Once you are back and want to retrieve working need to type the below command:

git stash pop

Cherry-pick:-

Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes. For example, say a commit is accidentally made to the wrong branch. You can switch to the correct branch and cherry-pick the commit to where it should belong.

git cherry-pick <Commit_Id>

Resolving Conflicts:-

When two branches are trying to merge, and both are edited at the same time and in the same file, Git won't be able to identify which version to take for changes. Such a situation is called a merge conflict. If such a situation occurs, it stops just before the merge commit so that you can resolve the conflicts manually.

Task-01

  • 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.

Used git stash to save the changes without committing them.

Go to the other repo do some changes and commits and then come back to the temp branch and use git stash pop command to bring the changes back and apply them on top of the new commits.

  1. Task 2:-

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

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

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

    3. Line3>> This is the advancement of the previous feature

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

    4. Line4>> Feature 2 is completed and ready for release

      Commit this with the message “ Feature2 completed”

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

More from this blog

DevOps

19 posts