{"id":16736237,"url":"https://github.com/flexdinesh/git-handbook","last_synced_at":"2026-01-03T02:07:26.529Z","repository":{"id":41155441,"uuid":"508510212","full_name":"flexdinesh/git-handbook","owner":"flexdinesh","description":"Handbook on how to use git commands and strategies that make life easier","archived":false,"fork":false,"pushed_at":"2022-06-29T23:43:11.000Z","size":3,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-22T10:14:01.852Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flexdinesh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-06-29T01:47:34.000Z","updated_at":"2024-09-24T03:30:45.000Z","dependencies_parsed_at":"2022-09-09T21:31:44.860Z","dependency_job_id":null,"html_url":"https://github.com/flexdinesh/git-handbook","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/flexdinesh%2Fgit-handbook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexdinesh%2Fgit-handbook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexdinesh%2Fgit-handbook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flexdinesh%2Fgit-handbook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flexdinesh","download_url":"https://codeload.github.com/flexdinesh/git-handbook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243790999,"owners_count":20348385,"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-10-13T00:08:45.706Z","updated_at":"2026-01-03T02:07:26.502Z","avatar_url":"https://github.com/flexdinesh.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git Handbook\n\nHandbook on how to use git commands and strategies that make life easier.\n\n## Sections\n\n- [Useful commands](#useful-commands)\n    - [Log](#log)\n    - [Branch](#branch)\n    - [Rebase](#rebase)\n    - [Push](#push)\n    - [Commit](#commit)\n    - [Stash](#stash)\n    - [Reset](#reset)\n    - [Cherry Pick](#cherry-pick)\n- [Merge strategies](#merge-strategies)\n    - [Rebasing](#rebasing)\n\n## Useful commands\n\n### Log\n`git log --oneline --graph --decorate`\n\nView the log in a useful and concise way\n\n### Branch\n`git checkout -b branch-name-goes-here`\n\nCreate a new branch from current branch\n\n`git checkout branch-name`\n\nCheckout the code of existing branch\n\n`git checkout -`\n\nCheckout previous branch \n\n### Rebase\n`git rebase main`\n\nRebase current branch against main\n\n`git rebase --abort`\n\nAbort current rebase in progress and revert to the state before rebase\n\n`git rebase --continue`\n\nAfter resolving merge conflicts during a rebase, continue with rebasing.\n\n`git rebase -i HEAD~3`\n\nEnter into interactive rebase mode with top 3 commits in current branch. This is how you squash/reword/discard commits in local branch.\n\n### Push\n\n`git push origin HEAD`\n\nPush the current branch to remote (the command will auto create remote ref if it doesn't exist)\n\n`git push origin HEAD --force-with-lease`\n\nForce push current branch to remote but don't override remote if someone else's changes are there. Need to do this after rebase, amend or anything that rewrites history\n\n### Commit\n`git commit --amend --no-edit`\n\nAmend the last commit (HEAD) with new changes. This will rewrite history so you will have to force push after this.\n\n`git commit --amend -m \"new desc\"`\n\nAmend the last commit (HEAD) with a new commit message. This will rewrite history so you will have to force push after this.\n\n### Stash\n\n`git stash save`\n\nSave all current tracked (staged and unstaged) files to stash. If you want to stash an untracked file (newly created file).\n\n`git stash save stash-name-goes-here`\n\nSave to stash with a descriptive name\n\n`git stash apply n`\n\nApply a particular stash index (0-n)\n\n### Reset\n\n`git reset --hard origin/main`\n\nReset current branch to the state of remote main\n\n`git reset --mixed HEAD~2`\n\nPop the last two commits in the current branch but preserve the changes from those commits in the staging area\n\n`git checkout .`\n\nDiscard all tracked local changes. Untracked files (newly created files) won't be affected.\n\n### Cherry Pick\n\n`git cherry-pick commit-hash`\n\nCherry pick that commit and apply it to current branch\n\n`git cherry-pick commit-hash commit-hash`\n\nCherry pick all listed commits and apply it on current branch\n\n## Merge Strategies\n\n### Rebasing\n\n**Step 1:** Make sure you don't have any merge commits in your current branch. If you do, please don't rebase or you'll have a hard time resolving conflicts repeatedly.\n\n**Step 2:** Make sure you don't have any uncommitted local changes. If you do, stash or commit them.\n\n**Step 3:** (from current branch) `git checkout main`\n\n**Step 4:** `git pull`  (This will fetch latest from origin/main and auto merge to local main. `pull` is just a shorthand for `fetch` and fast-forward `merge`)\n\n**Step 5:** `git checkout -` (This will take you back to your previous branch)\n\n**Step 6:** `git rebase main`\n\n(If you run into conflicts you will need to resolve it manually and stage the changes)\n\n**Step 7:** (once you stage the changes after resolving conflicts) `git rebase --continue`\n\n**Step 8:** Voila! You've now successfully rebased your branch against main.\n\nPlease note that after every rebase, your branch commit hashes get revised. So you will need to force push your branch to remote using `git push origin HEAD --force-with-leash` to let git know that this is intentional. If you don't use `--force-with-leash` your push will fail.\n\n(If you need to cancel your rebase at any point and revert to old state, you can always run `git rebase --abort` to do that)\n\n## License\n\nMIT © Dinesh Pandiyan\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflexdinesh%2Fgit-handbook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflexdinesh%2Fgit-handbook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflexdinesh%2Fgit-handbook/lists"}