Advance Git & GitHub for DevOps Engineers: Part-2

Advance Git & GitHub for DevOps Engineers: Part-2

Supercharge Your DevOps Workflow: Advanced Git & GitHub Practices

Git Stash:

Git #SourceTree | Git stash - Save changes away for later use. #Stashing -  YouTube

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:

🌳🚀 CS Visualized: Useful Git Commands - DEV Community

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:

resolve merge conflicts toolbar disappear · Issue #157325 ·  microsoft/vscode · GitHub

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.

Practical:

Task-01

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

git checkout -b dev2

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

git stash

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

git commit -m "stash commit"

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

cat db.txt

git add . 
git commit -m "final stash commit"

Task-02

  • In version01.txt of the development branch add the below lines after “This is the bug fix in the development branch” that you added in the previous blog practical and reverted to this commit.
git checkout dev
git branch

git log --oneline

  • Line2>> This is the advancement of the previous feature

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

cat version01.txt
git add .
git commit -m "Added feature2.2 in development branch"

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

    Commit this with the message “ Feature2 completed”

vim version01.txt
git add .
git commit -m "Feature2 completed"

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

Task-03

  • In the main branch Cherry pick Commit “Added feature2.2 in development branch” and added the below lines in it:
git cherry-pick 12c617d

cat version01.txt

git diff

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

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

  • Commit: Optimized the feature
git commit -m "Optimized the feature"

Thanks for reading my article. Have a nice day.

No alt text provided for this image

For updates follow me on LinkedIn: Swapnil Khairnar


Hashtags:

#90daysofdevops #devops #cloud #aws #awscloud #awscommunity #docker #linux #kubernetes #k8s #ansible #grafana #terraform #github #opensource #90daysofdevops #challenge #learningprogress #freelancer #linkedin #trainwithshubham #devopscommunity #cloudproviders #bash #bashshellscripting #awkward #shellscripting

Did you find this article valuable?

Support Swapnil Khairnar by becoming a sponsor. Any amount is appreciated!