In today's class, we will delve into the realm of advanced Git and GitHub. A comprehensive grasp of Git and GitHub is indispensable for streamlined code management and effective collaboration on projects.
Git Stash:
Git stash is a handy command that allows you to temporarily store changes you've made in your working directory without committing them. This feature becomes invaluable when you need to switch to a different branch to work on a separate task but aren't ready to commit the changes in your current branch.
Here's how to use Git stash: First, create a new branch and make some modifications. Then, employ the "git stash" command to save those alterations. This action removes the changes from your working directory and archives them in a new stash. You can retrieve and apply these changes later when needed. To keep track of your stashes, use the "git stash list" command.
Additionally, you can utilize "git stash drop" to delete a specific stash or "git stash clear" to remove all stashes.
Cherry-pick:
Git cherry-pick is a powerful command that enables you to choose specific commits from one branch and apply them to another. This is particularly valuable when you want to selectively integrate changes made in one branch into another.
To utilize "git cherry-pick," start by creating two new branches and making commits to them. Then, use the "git cherry-pick <commit_hash>" command to select and apply the specific commits from one branch to the other.
Resolving Conflicts:
Conflicts can arise during branch merges or rebase when branches have diverged, requiring manual intervention to resolve them before Git can proceed with the merge or rebase operation. You can identify conflicted files using the "git status" command, examine the differences between conflicting versions with "git diff," and use "git add" to include the resolved files.
Task-01
Step 1: Create a new branch and make some changes to it.
Step 2: Use git stash to save the changes without committing them.
Step 3: Switch to a different branch, make some changes and commit them.
Step 4: Use git stash pop to bring the changes back and apply them on top of the new commits.
Real changes are applied on top of the new commit made in the dev branch.
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.
Line2>> After bug fixing, this is the new feature with minor alteration”
Commit this with message “ Added feature2.1 in development 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 the message “ Feature2 completed”
Now we could see changes reflected in Dev branch
All these commit messages should be reflected in Production branch too which will come out from Master branch (Hint: try rebase).
-
With rebase we have successfully pulled changes from dev branch to main branch.
Thanks,
Kishor Chavan