Advance Git & GitHub

Advance Git & GitHub

Git Branching

Git branching is a feature of the Git version control system that allows us to work on different versions of your project at the same time. Branches allow us to develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.

Git Revert and Reset

Git revert and reset are two different ways to undo changes in a Git repository.

Git revert is used to undo a single commit or a series of commits. When you revert a commit, Git creates a new commit that undoes the changes introduced by the previous commit. This allows you to keep a record of the fact that you have undone a previous commit. This is useful when you want to undo changes that have already been pushed to a remote repository and you don't want to rewrite the repository history.

Git reset, on the other hand, is used to undo changes to the staging area or the working directory. There are three types of git reset: soft, mixed, and hard.

  • A soft reset moves the HEAD pointer to a previous commit without changing the staging area or working directory.

  • A mixed reset moves the HEAD pointer and resets the staging area, but leaves the working directory unchanged.

  • A hard reset moves the HEAD pointer, resets the staging area, and discards changes in the working directory.

Git Rebase and Merge

Git rebase and merge are two different ways to integrate changes from one branch into another branch in a Git repository

Git merge is the most commonly used way to integrate changes. When you merge a branch, Git creates a new commit that combines the changes from the two branches. This creates a merge commit that has two parent commits, one from each branch.

Git rebase, on the other hand, rewrites the history of the branch being rebased. When you rebase a branch, Git applies the changes from one branch onto another branch as if they were made in sequence. This creates a linear history without any merge commits.

The main difference between git merge and rebase is that merge creates a new commit that merges two branches, while rebase applies the changes from one branch on top of another branch's changes.

Task 1:

Add a text file called version01.txt inside the Devops/Git/ with “This is first feature of our application” written inside. This should be in a branch coming from master, [hint try git checkout -b dev], swithch to dev branch ( Make sure your commit message will reflect as "Added new feature"). [Hint use your knowledge of creating branches and Git commit command]

  • version01.txt should reflect at local repo first followed by Remote repo for review. [Hint use your knowledge of Git push and git pull commands here]

Add new commit in dev branch after adding below mentioned content in Devops/Git/version01.txt: While writing the file make sure you write these lines

  • 1st line>> This is the bug fix in development branch

  • Commit this with message “ Added feature2 in development branch”

  • 2nd line>> This is gadbad code

  • Commit this with message “ Added feature3 in development branch

  • 3rd line>> This feature will gadbad everything from now.

  • Commit with message “ Added feature4 in development branch

Restore the file to a previous version where the content should be “This is the bug fix in development branch” [Hint use git revert or reset according to your knowledge]

Adding text to the version01.txt file

reflecting version01.txt from local repo first followed by Remote repo for review.

Commit content to the dev branch

Adding content to the dev branch

pushing the content to the central repository

Restoring the file to a previous version where the content should be “This is the bug fix in development branch

Task 2:

  • Demonstrate the concept of branches with 2 or more branches with screenshot.

  • add some changes to dev branch and merge that branch in master

  • as a practice try git rebase too, see what difference you get.

Concept of branches

  • Use a branch to isolate development work without affecting other branches in the repository. Each repository has one default branch, and can have multiple other branches. You can merge a branch into another branch using a pull request.

    Branches allow you to develop features, fix bugs, or safely experiment with new ideas in a contained area of your repository.

  • 1.To show all branches:

    git branch

    2.Creating a new branch:

    git branch <branch_name>

    3. move to specific branch:

    git checkout <branch_name>

    4. To delete a branch:

    git branch -d <branch_name>

    5. for creating and going to that branch:

    git checkout -b <branch_name>

  • adding some changes to dev branch and merge that branch in master

  • as a practice try git rebase too, see what difference you get.

  • created the rebasefile , added in staging area and then commit.

    rebase the dev

    THAT'S ALL FOR TODAY'S LEARNING I HOPE YOU LEARN SOMETHING FROM THIS BLOG.