Advance Git & GitHub for DevOps Engineers.

Advance Git & GitHub for DevOps Engineers.

So today we will explore more into GIT, We will learn about the topic GIT Branching, GIT Revert and Reset, Git Rebase and Merge.

So here we begins with GIT Branching

Git Branching

Git branching is a core feature that allows developers to create separate lines of development within a Git repository. Branches are essentially lightweight pointers to a specific commit (snapshot) in the repository's history. Git branching enables parallel development, facilitates collaboration, and supports agile development practices by isolating workstreams and allowing for efficient project management within version control. Here’s what you need to know about Git branching:

  • Purpose: Branches enable developers to work on new features, bug fixes, or experiments without affecting the main codebase (often called the master or main branch).
  • Creating Branches: Developers can create branches using the git branch <branch-name> command. This creates a new branch named <branch-name> at the current commit.
  • Switching Branches: To switch between branches, use git checkout <branch-name> or git switch <branch-name>. This updates the working directory to reflect the chosen branch's state.
  • Merging: Once work on a branch is complete, changes can be merged back into the main branch using git merge <branch-name>. Git intelligently combines changes, resolving any conflicting modifications.
  • Branch Management: Use git branch to list branches, git branch -d <branch-name> to delete a branch once merged, and git branch -D <branch-name> to force delete a branch, even if unmerged.
  • Branching Strategies: Teams often use branching strategies like GitFlow (feature branches, release branches, etc.) or GitHub Flow (short-lived feature branches, continuous deployment).


Git Revert and Reset

In Git, revert and reset are both commands used to undo changes in a repository's history, but they work in different ways:

Git Revert

Git revert creates a new commit that undoes the changes made by a specific commit or range of commits. It effectively creates a new commit that inverses the specified changes, leaving the original commits intact in the history. Key points about git revert:

  • Usage: git revert <commit> or git revert <commit1>..<commit2>
  • Outcome: A new commit is created with changes that negate the specified commit(s).
  • Safety: Safe for use in shared repositories because it preserves history and does not rewrite existing commits.
  • Use Cases: Useful for reverting specific changes while preserving the rest of the commit history.

Git Reset

Git reset is used to reset the current branch to a specific state, typically an earlier commit. It can be used to undo changes by moving the branch pointer to a different commit, potentially altering the commit history. Key points about git reset:

  • Usage: git reset <commit>
  • Modes:Soft Reset: Moves branch pointer to specified commit, keeping staged changes.Mixed Reset: Moves branch pointer and unstages changes, but leaves working directory unchanged.Hard Reset: Moves branch pointer, unstages changes, and discards all changes in the working directory.
  • Caution: Rewrites commit history, so use with care, especially in shared repositories where it can cause confusion.

Choosing Between Git Revert and Reset

  • Revert is safer for undoing changes in shared repositories or when you want to preserve the commit history.
  • Reset is more powerful but should be used cautiously, especially when altering shared history or needing to discard changes entirely.

Both commands are essential tools for managing project history in Git, offering flexibility in undoing changes based on project needs and collaboration requirements.

git checkout

git checkout is used to discard the changes in the working repository.

Syntax - git checkout <filename>


Git Rebase and Merge

In Git, rebase and merge are both used to integrate changes from one branch into another, but they do so in different ways:

Git Merge

Git merge integrates changes from one branch (the source branch) into another branch (the target branch). It creates a new commit that combines the changes of the source branch with the target branch. Key points about git merge:

  • Usage: git merge <branch>
  • Outcome: Creates a merge commit that combines changes from the specified branch into the current branch.
  • History: Preserves the commit history of both branches, showing a merge commit that represents the integration point.
  • Workflow: Commonly used for integrating feature branches into a main development branch (e.g., master or main).

Git Rebase

Git rebase rewrites the commit history by moving or combining commits from one branch onto another base branch. It effectively transfers the changes of the current branch to the tip of the base branch. Key points about git rebase:

  • Usage: git rebase <base>
  • Outcome: Reapplies commits from the current branch on top of the base branch, creating a linear history.
  • History: Results in a cleaner, linear history without merge commits (if rebasing feature branches).
  • Workflow: Preferred for feature branches to keep a clean history before merging into the main branch.

Choosing Between Git Rebase and Merge


  • Merge is suitable for integrating branches where preserving individual commit history and branch context is important, such as for long-lived branches or collaboration involving multiple developers.
  • Rebase is useful for maintaining a clean and linear history, especially for feature branches or when preparing changes for integration into a shared repository, like master or main.

Both git merge and git rebase are powerful tools in Git workflows, offering flexibility in managing project branches and history based on project needs, collaboration styles, and development practices.



Panayiotis Kotrokois

? ???? ???? ???? Top LinkedIn Marketing Strategist & Coach ?? Strategic 360 Marketing Advisor & Mentor | ?Empowered 60+ Global Brands & Organizations | ???? CMO/CCSO @7L & CMO @MG

3 个月

Impressive journey. Git mastery boosts efficiency, collaboration, maintainability.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了