Day 10 Task: Advance Git & GitHub for DevOps Engineers.

Git Branching

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.

Git Revert and Reset

Two commonly used tools that git users will encounter are those of git reset and git revert . The benefit of both of these commands is that you can use them to remove or edit changes you’ve made in the code in previous commits.

What Is Git Rebase?

Git rebase is a command that lets users integrate changes from one branch to another, and the logs are modified once the action is complete. Git rebase was developed to overcome merging’s shortcomings, specifically regarding logs.

What Is Git Merge?

Git merge is a command that allows developers to merge Git branches while the logs of commits on branches remain intact.

The merge wording can be confusing because we have two methods of merging branches, and one of those ways is actually called “merge,” even though both procedures do essentially the same thing.

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]

Here are the steps to add a text file called version01.txt inside the Devops/Git/ directory with "This is first feature of our application" written inside. This should be in a branch coming from master and you should switch to the dev branch with a commit message reflecting "Added new feature":

  1. Open a terminal or command prompt.

  2. Navigate to the directory where you want to create the Git repository.

  3. Run the command git init. This will initialize a new Git repository in the current directory.

  4. Run the command git checkout -b dev. This will create a new branch called dev and switch to it.

  5. Create a new file called version01.txt in the Devops/Git/ directory. You can do this by running the command touch Devops/Git/version01.txt.

  6. Open the version01.txt file in a text editor.

  7. Write “This is first feature of our application” inside the file.

  8. Save the file and close the text editor.

  9. Add the file to the staging area by running the command git add Devops/Git/version01.txt.

  10. Commit the changes to the repository with a commit message reflecting “Added new feature” by running the command git commit -m "Added new feature".

  11. Push the changes to the remote repository by running the command git push -u origin dev.

Now you have created a new branch called dev and added a new file called version01.txt with the message "This is first feature of our application" inside it. The changes have been committed to the repository with a commit message reflecting "Added new feature”. The changes have also been pushed to the remote repository.

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”

  1. Run the command git checkout dev. This will switch to the dev branch.

  2. Open the version01.txt file in a text editor.

  3. Add the content “This is the bug fix in development branch” as the first line in the file.

  4. Save the file and close the text editor.

  5. Add the changes to the staging area by running the command git add Devops/Git/version01.txt.

  6. Commit the changes to the repository with a commit message reflecting “Added feature2 in development branch” by running the command git commit -m "Added feature2 in development branch".

  7. Push the changes to the remote repository by running the command git push origin dev.

  • 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

Do steps 03 and 06 with change in content of text and message while commiting the changes.

Task 2:

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

Add some changes to a development (dev) branch and then merge that branch into the master branch, you can follow these steps using Git:

  1. Make sure you are in the master branch:

     git checkout master
    
  2. Create a new branch for your development work (if you haven't already created the dev branch):

     git checkout -b dev
    
  3. Make your changes in the dev branch. Commit your changes as you go along:

     # Make changes to your code
     git add .
     git commit -m "Your commit message"
    
  4. After you've made and committed all the changes you want in the dev branch, switch back to the master branch:

     git checkout master
    
  5. Merge the dev branch into the master branch:

     git merge dev
    
  6. Resolve any merge conflicts if they occur. Git will guide you through this process.

  7. After resolving conflicts (if any), commit the changes in the master branch to complete the merge.

  8. Finally, push the changes to your remote repository (if you're using one):

     git push origin master
    

Now, your changes from the dev branch have been merged into the master branch. It's important to note that this is a simplified workflow, and in a real-world scenario, you might want to use pull requests or other processes to ensure code quality and collaboration with your team before merging into the master branch.