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

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

Advance Git & GitHub for DevOps Engineers: Part-2

Git Stash:

Git stash is a command that allows you to temporarily save changes you have made in your working directory, without committing them. This is useful when you need to switch to a different branch to work on something else, but you don't want to commit the changes you've made in your current branch yet.

To use Git stash, you first create a new branch and make some changes to it. Then you can use the command git stash to save those changes. This will remove the changes from your working directory and record them in a new stash. You can apply these changes later. git stash list command shows the list of stashed changes.

You can also use git stash drop to delete a stash and git stash clear to delete all the stashes

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_hash> 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

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

Now making changes in dev branch file and saving it for later using git stash (here we are using git stash command and file.txt is not committed for push)

Creating another branch Prod ( from master )and making some changes and committing it

Back to the dev branch, where we left our changes aside by using git stash command

Now use git stash apply to bring the changes back and apply them on top of the new commits.


Task 2

From the master branch commit a file devops/git/version01.txt

Content " This is a new feature of our application "

Commit message " Added new feature "

Create a dev branch from master branch

From the dev branch commit a file devops/git/version01.txt

Content " This is the bug fix in development branch**"**

Commit message " Added new feature2 in dev branch "

From the dev branch commit a file devops/git/version01.txt

Content " After bug fixing, this is the new feature with minor alteration"

Commit message " Added feature2.1 in dev branch "

From the dev branch commit a file devops/git/version01.txt

Content " This is the advancement of previous feature"

Commit message " Added feature2.2 in dev branch "

From the dev branch commit a file devops/git/version01.txt

Content " Feature 2 is completed and ready for release "

Commit message " feature2 completed "

Creating a prod branch from master and merging/rebase master with dev branch

I have used merge command here

Using rebase command


Task 3

Checking the git log

cherry-pick bb9b39a Commit “Added feature2.2 in development branch”

resolving the conflict and committing new line after line 3


Cherry-Pick

I want to cherry-pick some commits from prod branch to master branch

Checking logs of prod branch and picking a single commit id to use cherry-pick command

Let's take b15ddba "feature2 completed", copy the id

Switching the master branch and using cherry-pick command to bring the changes from prod branch to master