Advance Git And GitHub

ยท

3 min read

Advance Git And GitHub

Git branching

Git branching is a feature that allows you to create multiple versions of your codebase at the same time. This is useful for a variety of tasks, such as:

  • Developing new features without affecting the main codebase

  • Fixing bugs in isolation

  • Experimenting with different ideas

  • Collaborating with other developers on different parts of the codebase

Git Revert and Reset

]
Git revert and reset are two commands that can be used to undo changes in a Git repository. However, they work in different ways.

git revert

The git revert command creates a new commit that undoes the changes made by the specified commit. This means that the commit history is preserved, and other developers can still see the changes that were made, even though they have been undone.

To use the git revert command, simply specify the commit that you want to undo: git revert <commit-hash>

This will create a new commit with the message "This reverts commit <commit-hash>".

git reset

The git reset command moves the HEAD pointer back to the specified commit. This means that the commit history is rewritten, and any commits that were made after the specified commit are discarded.

To use the git reset command, simply specify the commit that you want to move the HEAD pointer back to: git reset <commit-hash>

This will reset the HEAD pointer to the specified commit, and any commits that were made after the specified commit will be discarded.

Git Rebase and Merge

rebase and merge are two commands that can be used to combine changes from one branch into another. However, they work in different ways.

git rebase

The git rebase command moves the commits from one branch onto the tip of another branch. This means that the commit history is rewritten, and the two branches will have a linear history.

To use the git rebase command, simply specify the branch that you want to rebase onto: git rebase <branch-name>

This will move the commits from the current branch onto the tip of the specified branch.

git merge

The git merge command combines the changes from two branches into a single branch. This is done by creating a new commit that contains the changes from both branches.

To use the git merge command, simply specify the branch that you want to merge into the current branch: git merge <branch-name>

This will create a new commit that contains the changes from both branches.

Which one should you use?

In general, you should use git rebase to combine changes from one branch into another when you are working on your branch and you want to keep the commit history linear. You should use git merge when you are working on a shared branch and you want to preserve the commit history.


Hope it helps you

Follow for more

#git #github #GitAndGithub #linux #devops #cloud #DevOps #CloudComputing #AWS #GitvsGitHub #gitops

ย