Advance Git & GitHub for DevOps

Advance Git & GitHub for DevOps

Git Stash:

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. For example: $ git status On branch main Changes to be committed: new file: style.

Cherry-pick:

git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. 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.

Resolving Conflicts:

Git can handle most merges on its own with automatic merging features. A conflict arises 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. Conflicts will most likely happen when working in a team environment.

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.

Task-02

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

    1. on Day 10 and reverted to this commit:
    After bug fixing, this is the new feature with minor alteration.

  1. Commit the changes with the message "Added feature2.1 in development branch":
    git branch development
    git branch
    git add version01.txt
    git commit -m "Added feature2.1 in development branch"

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

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

    1. Add the following line after the previous change:
    This is the advancement of the previous feature.

  1. Commit the changes with the message "Added feature2.2 in development branch":
    git add version01.txt
    git commit -m "Added feature2.2 in development branch"

  1. Add the following line after the previous change:
    Feature 2 is completed and ready for release.

  1. Commit the changes with the message "Feature2 completed":
    git add version01.txt
    git commit -m "Feature2 completed"

  1. Switch to the production branch:
    git checkout production

  • All these commits messages should be reflected in Production branch too which will come out from Master branch

        git rebase development
    

    1. Push the changes to the remote repository:
    git push origin production

Task-03

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

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

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

    1. First, make sure you are on the Production branch:
    git checkout production

  1. Cherry-pick the commit using its SHA hash:
    git cherry-pick <commit-SHA>

  • Replace <commit-SHA> with the actual SHA hash of the "Added feature2.2 in development branch" commit.

    1. Once the cherry-pick is complete, open the file where you want to add the new lines and edit it:
    nano <file-name>

  1. Go to the line after Line3 and add the following text:
    This is the advancement of previous feature

  1. Go to the next line and add the following text:
    Added few more changes to make it more optimized

  1. Save and exit the file.

  2. Finally, commit the changes:

    git add <file-name>
    git commit -m "Added advancement and optimization to feature 2.2"

Thank you for Reading