πŸš€πŸ”—πŸ’» Advanced Git & GitHub for DevOps Engineers 🌐✨

πŸš€πŸ”—πŸ’» Advanced Git & GitHub for DevOps Engineers 🌐✨

Index

Β·

4 min read

πŸŒΏπŸ”„πŸš€ Git Branching
πŸ”„βͺπŸ”€ Git Revert and Reset
πŸ”„πŸ”€ Git Rebase and Merge
πŸ“Œ Task 1: πŸ› οΈ
πŸ“Œ Task 2: πŸ“‹
🌐✨Conclusion! πŸš€πŸŽ‰

Git BranchingπŸŒΏπŸ”„πŸš€

Git Branching involves creating isolated spaces for developing specific features without affecting the main codebase. Changes are integrated back into the main branch through merging, conflicts are addressed when necessary, obsolete branches are deleted, and visualization tools help understand the branching structure. πŸŒΏπŸš€

Git Revert and Reset

  1. Git Revert πŸ”„

    • Purpose: Undo a specific commit by creating a new commit that undoes the changes.

    • Command: git revert <commit-hash>

  2. Git Reset πŸ”€

    • Purpose: Move the branch pointer to a specific commit, discarding changes.

    • Commands:

      • git reset --soft <commit-hash>

      • git reset --mixed <commit-hash>

      • git reset --hard <commit-hash>

Git Revert undoes changes with a new commit, while Git Reset repositions the branch pointer, with options to preserve or discard changes. πŸ”„πŸ”€

Git Rebase

πŸ”„ Git Rebase : Reorganizes commit history by incorporating changes from one branch into another. It creates a cleaner, linear history by placing the local changes on top of the remote branch.

Command: git rebase <branch-name>

Purpose: Streamlines the commit history for a more cohesive and understandable narrative. πŸš€πŸ”„

πŸ”€ Git Merge

πŸš€ Git Merge: Integrates changes from one branch into another, creating a new commit that combines the histories of both branches.

Command: git merge <branch-name>

Purpose: Unites divergent lines of development, bringing changes together in a collaborative and organized manner. πŸ”€πŸŒ

πŸ“Œ Task 1: πŸ› οΈ

#make a directory
mkdir Devops
#change to devops
cd Devops
#for git dir
mkdir Git
# Navigate to the Git/ directory
cd Git/

# Create a new branch named 'dev' and switch to it
git checkout -b dev

# Create a text file called version01.txt and add the specified content
echo "This is the first feature of our application" > version01.txt

# Stage the changes
git add version01.txt

# Commit the changes with the specified commit message
git commit -m "Added new feature"

Add new commit in dev branch after adding below mentioned content in Devops/Git/version01.txt

# Navigate to the Devops/Git/ directory
cd Devops/Git/

# Switch to the 'dev' branch
git checkout dev

# Open version01.txt and add the specified content
#insted of echo we can use the vim version.txt
echo "This is the bug fix in development branch" >> version01.txt
# Stage the changes
git add version01.txt
# Commit the changes with the specified commit message
git commit -m "Added feature2 in development branch"

# Open version01.txt and add the specified content
echo "This is gadbad code" >> version01.txt
# Stage the changes
git add version01.txt
# Commit the changes with the specified commit message
git commit -m "Added feature3 in development branch"

# Open version01.txt and add the specified content
echo "This feature will gadbad everything from now." >> version01.txt
# Stage the changes
git add version01.txt
# Commit the changes with the specified commit message
git commit -m "Added feature4 in development branch"

# Push the changes to the remote repository
git push origin dev

These commands add new commits with the specified content to the 'dev' branch in the local repository and then push those changes to the remote repository. The changes will be reflected in the remote repository for review.

πŸ“Œ Task 2: πŸ“‹

The concept of branches with 2 or more branches

Adding some changes to dev branch and merge that branch in master

  1. Create a New Repository:

     # Create a new directory for your repository
     mkdir git-demo
    
     # Navigate to the newly created directory
     cd git-demo
    
     # Initialize a new Git repository
     git init
    
  2. Create and Switch to the 'dev' Branch:

     # Create and switch to the 'dev' branch
     git checkout -b dev
    
  3. Make Changes in 'dev' Branch:

     # Open a text editor and add some content to a file (e.g., file.txt)
     echo "Changes in dev branch" > file.txt
    
     # Stage and commit the changes
     git add file.txt
     git commit -m "Added changes in dev branch"
    
  4. Switch to 'master' Branch:

     code# Switch to the 'master' branch
     git checkout master
    
  5. Merge 'dev' Branch into 'master':

     code# Merge 'dev' into 'master'
     git merge dev
    
  6. Create a New Branch and Make Changes:

     # Create and switch to a new branch (e.g., 'feature-branch')
     git checkout -b feature-branch
    
     # Make changes in the new branch
     echo "Changes in feature branch" > feature.txt
     git add feature.txt
     git commit -m "Added changes in feature branch"
    
  7. Rebase 'feature-branch' onto 'master':

     # Switch to 'feature-branch'
     git checkout feature-branch
    
     # Rebase 'feature-branch' onto 'master'
     git rebase master
    

    Resolve any conflicts if prompted.

     # Continue with the rebase
     git rebase --continue
    

    The rebase integrates the changes from 'master' into 'feature-branch,' providing a linear commit history.

🌐✨Conclusion! πŸš€πŸŽ‰

Mastering Git and GitHub is crucial for DevOps engineers. Git branching, hooks, and advanced merge strategies enhance collaboration. Practical tasks like creating branches and leveraging Git rebase offer hands-on experience. Integrating these practices elevates development efficiency. Happy learning! πŸš€πŸŒ

Β