๐ท Git Stash:
Git stash serves as a command enabling the temporary preservation of changes made in the working directory without committing them. This proves beneficial when necessitating a switch to a different branch for alternate work, while deferring the commitment of current branch changes.
To utilize Git stash, start by creating a new branch and implementing modifications. Next, execute the command 'git stash' to save these alterations. This action removes the changes from the working directory, cataloging them in a new stash. Subsequently, these stashed changes can be applied later. Employ 'git stash list' to display the catalog of stashed changes. Additionally, 'git stash drop' allows the deletion of a specific stash, while 'git stash clear' deletes all stashes.
๐ท Cherry-pick:
Git cherry-pick is a command offering the selection of specific commits from one branch for application to another. This feature proves valuable in selectively applying alterations made in one branch to another.
To leverage git cherry-pick, create two new branches and perform commits in each. Then, utilize 'git cherry-pick <commit_hash>' to select and apply specific commits from one branch to the other.
๐ท Resolving Conflicts:
Conflicts may arise during branch merges or rebases when branches diverge, necessitating manual resolution before git can continue. Utilize 'git status' to display files containing conflicts. Employ 'git diff' to view discrepancies between conflicting versions, while 'git add' aids in adding the resolved files.
๐ Practice Example for Git Stash:
๐ท Task Instructions:
Create a New Branch and Apply Changes:
๐ธ Begin by creating a new branch in your Git repository.
๐ธ Implement alterations or additions within this new branch.
Save Changes Without Committing Using Git Stash:
๐ธ Utilize 'git stash' to preserve the changes made in the current working directory without committing them.
Switch to Another Branch and Commit Changes:
๐ธ Shift to a different branch in your repository.
๐ธ Make new modifications or additions within this branch.
๐ธ Commit these changes using git commit.
Apply Stashed Changes to the Current Branch:
๐ธ Apply the stashed changes onto the present branch and on top of the recent commits.
๐ธ Use git stash pop to retrieve the saved changes and incorporate them into the current branch.