Exercises Directory

EXERCISE: under-control

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download under-control command.

Your task:

When you download a Git-Mastery exercise, the output will tell you which directory you need to cd into, for you to start the exercise:

Put the folder under-control/control-me under Git's control (i.e., initialise a repository in the control-me folder).


To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/under-control folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/under-control folder and run the gitmastery progress reset command.


EXERCISE: stage-fright

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download stage-fright command.

Your task:

The attendance repo has three unstaged files. Stage them.


To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/stage-fright folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/stage-fright folder and run the gitmastery progress reset command.


EXERCISE: staging-intervention

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download staging-intervention command.

Your task:

In the repo intervention given, unstage the following files: adam.txt, josh.txt, mary.txt. Keep other files staged.


To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/staging-intervention folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/staging-intervention folder and run the gitmastery progress reset command.


EXERCISE: grocery-shopping

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download grocery-shopping command.

Your task:

In the shopping-list repo given, there is a shopping-list.txt.

  1. Edit it to remove at least one item from the shopping list and add at least one new item to the shopping list.
  2. Stage the change and commit it.

To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/grocery-shopping folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/grocery-shopping folder and run the gitmastery progress reset command.


EXERCISE: remote-control

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download remote-control command.

Your task:

  1. As per the usual practice, cd into the remote-control folder.
  2. Run gitmastery verify command.
  3. Take note of the repo name provided by Git-Mastery app (in its response).
  4. Create a new public GitHub repository using the repo name given.
  5. Provide the URL of that remote (without the .git at the end) when prompted
    e.g., https://github.com/johndoe/gitmastery-johndoe-remote-control

To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/remote-control folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/remote-control folder and run the gitmastery progress reset command.


To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download link-me command.

Your task:

In the link-this repo provided, add the git-mastery/link-me repository as a remote named upstream.


To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/link-me folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/link-me folder and run the gitmastery progress reset command.


EXERCISE: push-over

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download push-over command.

Your task:

Create a new commit on the main branch of the local repo in push-this folder, and push the updated main branch to the remote.


To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/push-over folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/push-over folder and run the gitmastery progress reset command.


EXERCISE: ignoring-something

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download ignoring-something command.

Your task:

1. Update the .gitignore file (inside the files/ folder) to reflect the following requirements:

  • Git should ignore every file in the many/ folder except the file many/file22.txt.
  • why_am_i_hidden.txt should not be ignored by Git.
  • ignore_me.txt should be ignored by Git.
  • Git should ignore any runaway.txt file in this/ and any of its current and future subfolders (hint: use a pattern).

2. Commit the updated .gitignore file.


To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/ignoring-something folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/ignoring-something folder and run the gitmastery progress reset command.


EXERCISE: fork-repo

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download fork-repo command.

Your task:

Fork the repo https://github.com/git-mastery/gm-shapes to your GitHub account, while retaining the original repo name gm-shapes.


To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/fork-repo folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/fork-repo folder and run the gitmastery progress reset command.


EXERCISE: clone-repo

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download clone-repo command.

Your task:

  1. Fork the repo https://github.com/git-mastery/gm-shapes to your GitHub account, if you haven't done so already. Retain the original repo name gm-shapes.
  2. Clone the fork to your computer, placing it in the folder clone-repo/shapes (note how the target folder is shapes, not gm-shapes).
    If you did this step correctly, you should now have local repo shapes.
  3. Set up a remote named upstream in that shapes repo, to point to the upstream repo git-mastery/gm-shapes.

To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/clone-repo folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/clone-repo folder and run the gitmastery progress reset command.


EXERCISE: fetch-and-pull

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download fetch-and-pull command.

Your task:

You have been given a clone of the git-mastery/gm-shapes repo.

  1. Another developer Alice has created a remote copy of this repo at https://github.com/git-mastery/gm-shapes-alice which seems to have an additional commit in the main branch.
    • Add that repo as a remote named alice-upstream.
    • Bring over Alice's additional commit to your repo.
  2. Alice's friend Bob has copied Alice's repo to https://github.com/git-mastery/gm-shapes-bob, and added one more commit.
    • Add that repo as another remote named bob-upstream.
    • Download the metadata about this new commit (i.e., fetch, not pull or merge) to your repo.

To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/fetch-and-pull folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/fetch-and-pull folder and run the gitmastery progress reset command.


EXERCISE: side-track

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download side-track command.

Your task:

While you are working on a small Python project in the branch-me repo, you discovered two bugs. You wish to fix them in a separate branch named bug-fix, as two separate commits.

The steps to follow are given below:

This repo uses main (not master) as the default branch.

  1. Create a branch named bug-fix.
    Switch to that branch.
  2. Update the greet.py file so that the greet function uses the name variable in the output, as follows:
    -    print("Hi Alice")
    +    print(f"Hi {name}")
    
    Commit the changes.
  3. Update the calculator.py file such that the add function returns the sum of two numbers, as follows:
     def add(a, b):
    -    return a - b
    +    return a + b
    
    Commit the changes.
  4. Switch back to the main branch.

The final result should be something like this:

gitGraph BT:
    %%{init: { 'theme': 'default', 'gitGraph': {'mainBranchName': 'main'}} }%%
    commit id: "[HEAD → main] ..."
    branch bug-fix
    commit id: "Fix greet.py"
    commit id: "[feature] Fix calculator.py"
    checkout main

To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/side-track folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/side-track folder and run the gitmastery progress reset command.


EXERCISE: branch-bender

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download branch-bender command.

Your task:

Do the following operations in the given webapp repo, in the given order:

  1. Merge feature/login onto the main branch, while ensuring a merge commit is created (i.e., no fast-forwarding).
  2. Merge feature/dashboard onto the main branch.
  3. Merge feature/payments onto the main branch.

The final result should look like this:

gitGraph
commit
branch feature/login
checkout main
branch feature/dashboard
checkout main
branch feature/payments
checkout feature/login
commit
commit
checkout main
merge feature/login
checkout feature/dashboard
commit
commit
commit
checkout main
merge feature/dashboard
checkout feature/payments
commit
commit
checkout main
merge feature/payments

To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/branch-bender folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/branch-bender folder and run the gitmastery progress reset command.


EXERCISE: conflict-mediator

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download conflict-mediator command.

Your task:

The given repo conflict has an unmerged branch josh and a merged branch john.
Merge branch josh onto main. This will result in a merge conflict in the script.py file.
Resolve the merge conflict and complete the merge.
The intended outcome is print('Hello Everyone and World!').


To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/conflict-mediator folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/conflict-mediator folder and run the gitmastery progress reset command.


EXERCISE: branch-rename

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download branch-rename command.

Your task:

In the rename-this repo, rename the login branch to feature/login.

Expected result:

gitGraph BT:
    commit id: "m1"
    commit id: "m2"
    branch feature/login
    commit id: "b1"
    checkout main
    commit id: "[HEAD → main] m3"
    checkout feature/login
    commit id: "[feature/login] b2"

To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/branch-rename folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/branch-rename folder and run the gitmastery progress reset command.


EXERCISE: branch-delete

To download the exercise:

  • Navigate inside the gitmastery-exercises folder.
  • Run gitmastery download branch-delete command.

Your task:

  1. Delete the optimization-approach-1 branch.
  2. Delete the optimization-approach-2 branch as well.

Expected outcome:

gitGraph BT:
    commit id: "Implement loading"
    commit id: "Fix loading bug"
    branch _
    commit id: "Apply bubble sort"
    commit id: "Fix sorting bug"
    checkout main
    merge _ id: "[HEAD → main] Merge ...'...approach-1"

To verify your work:

  • Navigate to anywhere inside the gitmastery-exercises/branch-delete folder (or any sub-folder of it).
  • Run the gitmastery verify command.

To reset the exercise and start over, navigate to the gitmastery-exercises/branch-delete folder and run the gitmastery progress reset command.