Advanced Git and GitHub for DevOps

Advanced Git and GitHub drive seamless collaboration, precise version control, and automation in DevOps.

Advanced Git and GitHub for DevOps

Git Branching:

Git branching lets developers work on different tasks simultaneously without disrupting the main code. It's easy and powerful.

  • git branch command in Git is used to list, create, or delete branches in a repository.

    • List Branches:

        git branch
      

    • Create a New Branch:

        git branch dev
      
    • Switch to a Branch:

        git checkout dev
      

    • Create and Switch to a New Branch:

        git checkout -b new-branch-name
      

    • Delete a Branch:

        git branch -d new-dev
      

    • Force Delete a Branch:

        git branch -D new-dev
      
  • git switch command creates a new branch and switches your working directory to this branch, allowing you to start working on it immediately.

      git switch dev
    

  • git merge integrates changes from one branch into another, combining their modifications.

  • git rebase is a Git command used to combine, rearrange, or modify the commit history of a branch.

  • git revert command in Git is used to create a new commit that undoes the changes made in a previous commit.

  • git reset is used to undo changes: --soft preserves changes, --mixed resets staging, --hard discards changes entirely.

  • git cherry-pick is used to apply specific commits from one branch to another. It allows you to pick individual commits and apply them to your current branch.

    Example:

  • Git stash temporarily saves changes, allowing you to switch branches or work on other tasks, and later apply the changes back.

  • git clean is a command in Git that is utilized to eliminate untracked directories and files from the working directory.

      git clean -n
    
  • git reflog displays a log of reference (branch and tag) changes, helpful for recovering lost commits or branches.

      git reflog
    

  • Squash in Git combines multiple commits into one for a cleaner history.

      git rebase -i HEAD~3
    

    Happy learning (^_^)

Did you find this article valuable?

Support Devops Related Articles by becoming a sponsor. Any amount is appreciated!