{"id":23015433,"url":"https://github.com/hirwa13/git-exercise","last_synced_at":"2025-07-18T10:33:12.573Z","repository":{"id":240200350,"uuid":"800443829","full_name":"HIRWA13/Git-exercise","owner":"HIRWA13","description":"Advanced Git Exercises","archived":false,"fork":false,"pushed_at":"2024-05-19T09:20:17.000Z","size":42,"stargazers_count":2,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-23T03:54:35.506Z","etag":null,"topics":["git","github"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HIRWA13.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-14T10:48:43.000Z","updated_at":"2025-02-27T13:34:26.000Z","dependencies_parsed_at":"2024-12-15T17:04:53.327Z","dependency_job_id":null,"html_url":"https://github.com/HIRWA13/Git-exercise","commit_stats":null,"previous_names":["hirwa13/git-exercise"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/HIRWA13/Git-exercise","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HIRWA13%2FGit-exercise","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HIRWA13%2FGit-exercise/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HIRWA13%2FGit-exercise/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HIRWA13%2FGit-exercise/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HIRWA13","download_url":"https://codeload.github.com/HIRWA13/Git-exercise/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HIRWA13%2FGit-exercise/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265742656,"owners_count":23820879,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git","github"],"created_at":"2024-12-15T11:12:18.256Z","updated_at":"2025-07-18T10:33:12.553Z","avatar_url":"https://github.com/HIRWA13.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git Exercises\n\nThis comprehensive exercise combines essential Git skills, from manipulating history to advanced branching strategies.\n\n### Resources\n\nBefore starting this exercise, Go through **Branching Model** and **Contribution rules and git flow** resources. When attempting the challenges, Try to use what you read as much as you can.\n\n- [Branching Model](https://classic-cobalt-104.notion.site/Branching-model-c1f8f9686eef4d3594a8c1ca4955d451)\n- [Contribution rules and git flow](https://classic-cobalt-104.notion.site/Contribution-rules-and-git-flow-0505d789170f4c0a8b7b5d7b41df7bf5)\n\n### Getting Started:\n\n1. **Create a New Git Repository:**\n   - Head over to GitHub and create a new repository. Clone this repository to your local machine.\n\n2. **Initialize Your Environment:**\n   - Open a terminal window and navigate to your cloned repository directory.\n   - Run the following commands to create some dummy files and commit them:\n\n   ```bash\n   touch test{1..4}.md\n   git add test1.md \u0026\u0026 git commit -m \"chore: Create initial file\"\n   git add test2.md \u0026\u0026 git commit -m \"chore: Create another file\"\n   git add test3.md \u0026\u0026 git commit -m \"chore: Create third and fourth files\"\n   ```\n   \n## Challenges:\n\n**Part 1: Refining Git History (10 Challenges)**\n\n1. **Missing File Fix:**\n\n   - Run `git status` and `git log` to assess the current state of your repository.\n   - From the status you will see that you forgot to add `test4.md` in the last commit.\n\n   **Challenge:** Recover from this error by staging/adding `test4.md` and amending the commit message with an appropriate description.\n\n2. **Editing Commit History:**\n\n   - It's crucial to maintain accurate commit messages. Modify the message from \"Create another file\" to \"Create second file\".\n\n   **Challenge:** Utilize interactive rebasing (`git rebase -i HEAD~2`) to edit the commit message and ensure clarity. learn more about git `rebase` [here](https://www.bryanbraun.com/2019/02/23/editing-a-commit-in-an-interactive-rebase/)\n\n3. **Keeping History Tidy - Squashing Commits:**\n\n   - Squashing combines multiple commits into a single one. Let's merge \"Create second file\" into \"Create initial file\" for a cleaner history.\n\n   **Challenge:** Use interactive rebasing with the `squash` command to achieve this. learn more about `squash` [here](https://mattstauffer.com/blog/squashing-git-commits-with-interactive-rebase/)\n\n4. **Splitting a Commit:**\n\n   - Imagine \"Create third and fourth files\" describes too much at once. Separate them for better tracking with two different commit messages: \"Create Third File\" and \"Create fourth file\".\n\n   **Challenge:** Leverage `git reset` to separate the files into individual commits with distinct messages. learn more about `splitting commits` [here](https://dev.to/timmouskhelichvili/how-to-split-a-git-commit-into-multiple-ones-3g6f)\n\n5. **Advanced Squashing:**\n\n   - Let's explore more complex squashing. Can you combine the last two commits (\"Create third file\" and \"Create fourth file\") into a single commit named \"Create third and fourth files\"?\n\n   **Challenge:** Utilize interactive rebasing with the `squash` command to achieve this advanced squash. **Check step 4**\n \n6. **Dropping a Commit:**\n\n   - We all make mistakes. Imagine needing to completely remove an unwanted commit from your history.\n\n   - Create a new file named `unwanted.txt` add some changes and commit it with a message like \"Unwanted commit\".\n\n   **Challenge:** Use `git rebase -i` to identify and remove the \"Unwanted commit\" commit, cleaning up your history. learn more about `dropping commits` [here](https://articles.assembla.com/en/articles/2941346-how-to-delete-commits-from-a-branch-in-git)\n\n7. **Reordering Commits:**\n\n   - Delve deeper into `git rebase -i`. Can you rearrange commits within your history using this command? learn more about `ordering commits` [here](https://www.youtube.com/watch?v=V9KpcGO7nLo)\n\n8. **Cherry-Picking Commits:**\n\n   - Create a branch, call it `ft/branch`, and add a new file named `test5.md` with some content. Commit these changes with a message like \"Implemented test 5\".\n   - Imagine you only desire a specific commit from `ft/branch`. Research and use `git cherry-pick` to selectively bring that commit into your current branch which is `main`.\n   \n   learn more about `cherry-pick` [here](https://www.freecodecamp.org/news/git-cherry-pick-avoid-duplicate-commits/)\n\n9. **Visualizing Commit History (Bonus):**\n\n   - Tools like `git log --graph` or a graphical Git client can help visualize your commit history. Explore these tools for a clearer understanding of your workflow.\n\n10. **Understanding Reflogs (Bonus):**\n\n   - Reflogs track Git operation history. Research about `git reflog` to learn how you can navigate back to previous states in your repository if needed.\n\n**Part 2: Branching Basics (10 Challenges)**\n\n1. **Feature Branch Creation:**\n\n   - Imagine working on a new feature named `ft/new-feature`. Let's establish a dedicated branch for it.\n\n   **Challenge:** Create a new branch named `ft/new-feature` and switch to that branch.\n\n2. **Working on the Feature Branch:**\n\n   - Create a new file named `feature.txt` in this branch and add some content to it.\n   - Commit these changes with a descriptive message like \"Implemented core functionality for new feature\".\n\n3. **Switching Back and Making More Changes:**\n\n   - It's common to switch between branches during development.\n\n   **Challenge:** Switch back to the `main` branch (previously master) and create a new file named `readme.txt` with some introductory content. Commit these changes with a message like \"Updated project readme\".\n\n\n4. **Local vs. Remote Branches:**\n\n   - So far, we've been working with local branches that exist on your machine. Research the concept of remote branches, which are copies of your local branches stored on a Git hosting platform like GitHub. [Learn](https://www.baeldung.com/ops/git-synchronize-local-remote-branches) how to push your local branches to remote repositories and pull changes from them to keep your local and remote repositories in sync.\n\n5. **Branch Deletion:**\n\n   - After merging or completing work on a feature branch, it's good practice to remove it.\n\n   **Challenge:** Delete the `ft/new-feature` branch once you're confident the changes are integrated into `main`.\n\n6. **Creating a Branch from a Commit:**\n\n   - You can also create a branch from a specific commit in your history.\n\n   **Challenge:** Use `git checkout -b ft/new-branch-from-commit commit-hash` (adjust the commit hash as needed) to create a new branch named `ft/new-branch-from-commit` starting from the commit two positions back in your history. learn more [here](https://www.novicedev.com/blog/create-git-branch-commit)\n\n7. **Branch Merging:**\n\n   - Now that you've completed work on your feature branch, it's time to integrate it into `main`.\n\n   **Challenge:** Merge the `ft/new-branch-from-commit` branch into the `main` branch. Address any merge conflicts that might arise.\n\n8. **Branch Rebasing:**\n\n   - Rebasing is another method to integrate changes from a feature branch. It rewrites your branch history by incorporating its commits on top of the latest commit in the target branch (`main` in our case).\n\n   **Challenge:** Try rebasing the `ft/new-branch-from-commit` branch onto the `main` branch. Remember, rebasing rewrites history, so use it with caution, especially in shared repositories. learn more about rebasing [here](https://www.atlassian.com/git/tutorials/rewriting-history/git-rebase#:~:text=From%20a%20content%20perspective%2C%20rebasing,them%20to%20the%20specified%20base.)\n\n9. **Renaming Branches:**\n\n   - Branch names can sometimes evolve. Let's rename `ft/new-branch-from-commit` to a more descriptive name.\n\n   **Challenge:** Use `git branch -m ft/new-branch-from-commit ft/improved-branch-name` to rename your branch.\n\n10. **Checking Out Detached HEAD:**\n\n   - In specific situations, you might need to detach HEAD from your current branch. Research `git checkout \u003ccommit-hash\u003e` (replace with the desired commit hash) to understand this concept.\n\n**Part 3: Advanced Workflows (10+ Challenges)**\n\n1. **Stashing Changes:**\n\n   - Imagine you're working on some changes in the `main` branch but need to attend to something urgent. You don't want to lose your uncommitted work.\n\n   **Challenge:** Stash your current changes in the `main` branch using `git stash`.\n\n2. **Retrieving Stashed Changes:**\n\n   - Later, when you're ready to resume working on those stashed changes, you can retrieve them.\n\n   **Challenge:** Apply the most recent stash back onto the `main` branch using `git stash pop`.\n\n3. **Branch Merging Conflicts (Continued):**\n\n   - Merge conflicts can arise when the same lines of code are modified in both branches being merged.\n\n   **Challenge:** Simulate a merge conflict scenario (you can create conflicting changes in a file on both `main` and a new feature branch). Then, try merging again and resolve the conflicts manually using your text editor.\n\n4. **Resolving Merge Conflicts with a Merge Tool:**\n\n   - Explore using a merge tool like `git mergetool` to help you visualize and resolve merge conflicts more efficiently.\n\n5. **Understanding Detached HEAD State:**\n\n   - Detached HEAD refers to a state where your working directory is not associated with any specific branch. Research the implications and how to recover from this state using commands like `git checkout \u003cbranch-name\u003e`.\n\n6. **Ignoring Files/Directories:**\n\n   - You might have files or directories you don't want to track in Git. Create a `.gitignore` file to specify these exclusions.\n\n   **Challenge:** Add a pattern like `/tmp` to your `.gitignore` file to exclude all temporary files and directories from version control. more about `ignoring files` [here](https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files)\n\n7. **Working with Tags:**\n\n   - Tags act like bookmarks in your Git history. Create a tag to mark a specific point in your development.\n\n   **Challenge:** Use `git tag v1.0` to create a tag named `v1.0` on the current commit in your `main` branch.  [git tags](https://www.javatpoint.com/git-tags)\n\n\n8. **Listing and Deleting Tags:**\n\n   **Challenge:** Use `git tag` to list all existing tags. Then, use `git tag -d \u003ctag-name\u003e` to delete a specific tag (replace `\u003ctag-name\u003e` with the actual tag you want to remove).\n\n9. **Pushing Local Work to Remote Repositories:**\n\n   - Once you're happy with your local changes and branches, it's time to share them with others.\n\n   **Challenge:** Assuming you've set up a remote repository on a Git hosting platform (like GitHub), push the changes with the actual branch you want to push to push your local branch to the remote repository.\n\n10. **Pulling Changes from Remote Repositories:**\n\n   - Collaboration often involves pulling changes from the remote repository made by others.\n\n   **Challenge:** Navigate to Github and make some changes inside your `README` file that you created on your `main` branch and in your local environment use `git pull origin \u003cbranch-name\u003e` (replace `\u003cbranch-name\u003e` with the actual branch you want to pull) to fetch changes from the remote repository's `main` branch and merge them into your local `main` branch. Address any merge conflicts that might arise.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhirwa13%2Fgit-exercise","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhirwa13%2Fgit-exercise","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhirwa13%2Fgit-exercise/lists"}