Git_Intermediate
Git_Intermediate
git merge <branch> - Merge specified branch into the current branch.
Tutorial
The 'git merge <branch>' command is used to integrate changes from the specified branch into the
current branch. This operation combines the histories of both branches, allowing you to bring in
updates, features, or bug fixes made on the specified branch while preserving the history of commits.
Copy
Merge feature branch
git merge feature-branch
git rebase <branch> - Reapply commits from one branch onto another.
Tutorial
The 'git rebase <branch>' command is used to move or combine a sequence of commits to a new base
commit, which allows for a cleaner project history by incorporating changes from one branch onto
another. It's particularly useful when you want to update a feature branch with the latest updates from
the main branch before merging.
Copy
Example 1: Rebase a feature branch onto the main branch
git checkout feature-branch
git rebase main
git fetch - Download objects and refs from another repository. Tutorial
The 'git fetch' command downloads the latest changes from a remote repository without merging them
into the current branch. It updates the local copies of remote branches, allowing users to review
changes before integrating them into their local codebase.
Copy
Fetch from default remote repository
git fetch
advertisement
git cherry-pick <commit> - Apply the changes introduced by an existing
commit. Tutorial
The 'git cherry-pick <commit>' command allows you to select specific commits from one branch and
apply them to another branch. This is useful when you want to incorporate certain changes from a
different branch without merging all the changes from that branch. Cherry-picking helps maintain a
cleaner commit history by allowing targeted integration of changes.
Copy
Cherry-pick a single commit
git cherry-pick abc1234
Delete a tag
git tag -d v1.0
git diff - Show changes between commits, commit and working tree, etc.
Tutorial
The 'git diff' command is used to show the differences between various states of your repository. It can
be applied to compare changes between commits, between the working tree and index, or between
your current working directory and the last commit. This helps developers understand what
modifications have been made, review changes before committing, or assess differences between
branches.
Copy
Show changes in the working directory
git diff
Show changes between the working directory and the last commit
git diff HEAD