{"id":20645764,"url":"https://github.com/christopherkade/up-your-git-game","last_synced_at":"2025-08-20T06:37:58.585Z","repository":{"id":54715716,"uuid":"192494670","full_name":"christopherkade/up-your-git-game","owner":"christopherkade","description":"Project for an article about git rebase","archived":false,"fork":false,"pushed_at":"2021-02-02T18:53:47.000Z","size":2,"stargazers_count":9,"open_issues_count":1,"forks_count":38,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-17T09:35:10.513Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://dev.to/christopherkade/up-your-git-game-and-clean-up-your-history-4j3j","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/christopherkade.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}},"created_at":"2019-06-18T08:05:34.000Z","updated_at":"2023-11-28T11:53:23.000Z","dependencies_parsed_at":"2022-08-14T00:40:45.201Z","dependency_job_id":null,"html_url":"https://github.com/christopherkade/up-your-git-game","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christopherkade%2Fup-your-git-game","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christopherkade%2Fup-your-git-game/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christopherkade%2Fup-your-git-game/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/christopherkade%2Fup-your-git-game/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/christopherkade","download_url":"https://codeload.github.com/christopherkade/up-your-git-game/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242714050,"owners_count":20173581,"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":[],"created_at":"2024-11-16T16:21:44.572Z","updated_at":"2025-03-09T15:56:51.192Z","avatar_url":"https://github.com/christopherkade.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003e This project's steps can be found on the [article](https://dev.to/christopherkade/up-your-git-game-and-clean-up-your-history-4j3j) or down bellow.\n\nThis repository will help you understand how rebase works by actually using it ! Don't worry if you make any mistakes, this is a clean slate, you can always re-clone it if you mess up.\n\n## Example 1: fixing up a commit with rebase\n\n**Scenario**: you have committed something that does not deserve a commit of its own, or you want to reduce the number of commits on your branch to one before making a pull request.\n\n- From the `master` branch, create a new branch.\n\n- Create a new file, its content doesn't really matter.\n\n- Commit that new file to your branch.\n\n```bash\ngit add index.js\ngit commit -m \"add index.js\"\n```\n\n- Update something in that file\n\n- Commit it again with a message such as \"update index.js\"\n\n- Run `git log`, as you can see, we now have 2 commits\n\nWe now want to `fixup` the `update` commit into the `add` commit, because this small change does not deserve a commit of its own.\n\nTo do so, we'll use the **interactive** mode of `git rebase`, which lets us apply the rebasing with a nice interface.\n\n- Run the rebase command like so:\n\n```bash\ngit rebase -i HEAD~2\n```\n\n`HEAD~2` means start from the last commit on the branch (the head) and go back 2 commits. If we wanted to manipulate more commits, we could change the value to the far right.  \nYou should now have an interface that looks something like this:\n\n![rebase interactive](https://thepracticaldev.s3.amazonaws.com/i/h4po6e92b0icvrpki9sz.png)\n\nDon't panic, this only shows you the two commits you are changing at the top, and the available commands bellow them.   \nBy default, the rebase interface uses Vim, to write in it, simply press the **i** key. You are now in **\"INSERT\"** mode. As we want to fixup the second commit in the first one, all we have to do is write `fixup` or `f` instead of `pick` in front of it. Our `update index.js` commit will now be squashed into the `add index.js` but only the `add index.js`'s message will be kept.\n\n- Update the second line like so:\n\n```bash\npick c0091ec add index.js\nf a19336e update index.js\n```\n\nNow, we want to apply the rebase, press **escape** to leave the **INSERT** mode, press **:** (colon) and enter **wq** for \"write\" and \"quit\" and press **ENTER** to apply these changes. The colon simply allows you to write commands for Vim to execute. \n\nThe following message should now appear in your console:\n\n\u003e Successfully rebased and updated refs/heads/{YOUR BRANCH NAME}.\n\nCheck your `git log`, you now have one beautiful and clean commit !\n\n- Finally, force push to that branch to apply the rebase to the remote server\n\n```bash\ngit push origin {BRANCH-NAME} -f\n```\n\nThe `-f` is essential as a rebase modifies your git history and requires to be forced.\n\n## Example 2: dropping a commit\n\nThese next 2 steps will be extremely similar to the first one because you now have the tools to do any kind of rebasing 🎉\n\n**Scenario**: you want to completely remove a commit\n\nWe'll drop the `add FILENAME` commit we previously made:\n\n- Run the rebase command\n\n```bash\ngit rebase -i HEAD~1\n```\n\n- Add a `d` or `drop` in front of the commit you wish to drop.\n\n![rebase drop](https://thepracticaldev.s3.amazonaws.com/i/nl7wqia23khpgf7by6jf.png)\n\n- Run `:wq` in your Vim editor (and check with `git log` that the commit was dropped)\n\n- Don't forget to force push it to your remote server 😀\n\n## Example 3: rewording a commit\n\nPretty similar, with one change.\n\n**Scenario**: you want to fix a typo or rewrite a commit's title or description\n\n- Create a random commit\n\n![git reword](https://thepracticaldev.s3.amazonaws.com/i/o88cmcyqj1596f52gyiy.png)\n\n- Run the rebase command\n\n```bash\ngit rebase -i HEAD~1\n```\n\n- Add a `r` or `reword` in front of the commit you wish to reword (no need to edit the title now).\n\n- Run `:wq` in your Vim  editor. This will open a similar editor with the commit(s) you wish to reword.\n\n![git reword 2](https://thepracticaldev.s3.amazonaws.com/i/ou14d5c0l0wisqix9wr2.png)\n\n- Update the commit's title and description to your will, run `:wq` and that's it ! Check with `git log` that the rewording was applied\n\n![git reword 3](https://thepracticaldev.s3.amazonaws.com/i/b1o6v4ichuc69ruig868.png)\n\n- Don't forget to force push it to your remote server 😀\n\n## Example 4: rebasing on `master`\n\n\u003e This example isn't reproduced in the Github project, but feel free to test it out.\n\n**Scenario**: you have multiple PRs (Pull Requests) open at the same time\n\n![rebase master screenshot](https://thepracticaldev.s3.amazonaws.com/i/ja8pn2wr7pl39yhaxf76.png)\n\nYou merge one PR, now, your second PR is not up to date with `master`, oh no !\n\n![rebase master screenshot 2](https://thepracticaldev.s3.amazonaws.com/i/bl9r2aajzi2384qa4f9n.png)\n\nThis very frequent scenario will have us rebase our second PR on `master` so that it gets the new code merged from the first PR.\n\n- From the branch you want to rebase (in our case, the second PR's branch), run the following:\n\n```bash\ngit fetch\n```\n\nThis downloads all the references our branch needs to apply the rebase. \n\n- Then, execute the rebase like so:\n\n```bash\ngit rebase origin/master\n```\n\n- Finally, run a `git push origin {MY-BRANCH} -f` to apply the rebase to our remote server\n\n![rebase master screenshot 3](https://thepracticaldev.s3.amazonaws.com/i/m220k16b638zl42xaqbo.png)\n\n\u003e Hurray !\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristopherkade%2Fup-your-git-game","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchristopherkade%2Fup-your-git-game","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchristopherkade%2Fup-your-git-game/lists"}