{"id":15984056,"url":"https://github.com/aminya/acutegit","last_synced_at":"2025-04-04T20:42:47.798Z","repository":{"id":66266843,"uuid":"194212822","full_name":"aminya/AcuteGit","owner":"aminya","description":"Git commands for operations not available in GitHub desktop","archived":false,"fork":false,"pushed_at":"2021-06-13T19:35:05.000Z","size":12537,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-10T05:22:31.142Z","etag":null,"topics":["git","push","rebase","squash","tutorial"],"latest_commit_sha":null,"homepage":"","language":"PowerShell","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/aminya.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},"funding":{"github":["aminya"],"polar":"aminya","patreon":"aminya"}},"created_at":"2019-06-28T05:38:53.000Z","updated_at":"2023-11-20T22:01:36.000Z","dependencies_parsed_at":"2023-03-10T23:46:41.918Z","dependency_job_id":null,"html_url":"https://github.com/aminya/AcuteGit","commit_stats":{"total_commits":47,"total_committers":1,"mean_commits":47.0,"dds":0.0,"last_synced_commit":"570e56f48e9844db6d81c3d989d0f682ca0bd3ab"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2FAcuteGit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2FAcuteGit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2FAcuteGit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aminya%2FAcuteGit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aminya","download_url":"https://codeload.github.com/aminya/AcuteGit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249598,"owners_count":20908211,"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","push","rebase","squash","tutorial"],"created_at":"2024-10-08T02:04:23.231Z","updated_at":"2025-04-04T20:42:47.775Z","avatar_url":"https://github.com/aminya.png","language":"PowerShell","readme":"# My Git Commands\nMy most used git commands for the operations that are not available through GitHub desktop software (https://desktop.github.com/) and [Atom GitHub](https://github.com/atom/github)\n\nFor github desktop documentation refer to:\nhttps://help.github.com/en/desktop/getting-started-with-github-desktop\n\n# Best practice to use Github for me:\nThis way you don't need to merge conflicts of pull requests and all that.\n\n* Check out to master\n\n\t```git\n\tgit checkout master\n\t```\n* Commit as many as you want using Github Desktop\n* Backup your master branch with its several commits\n\n\t```git\n\tgit checkout backup\n\t```\n* Check out to master again\n\n\t```git\n\tgit checkout master\n\t```\n* squash commits.\n\n\t```git\n\tgit rebase --interactive 6c36bcb04f22ad5fda24923bb58eac78ad1f0914\n\t```\n\tthen\n\t```git\n\tgit push --force\n\t```\n\n\n## Change text editor\nFor squashing commits you need this. Replace your text editor at least with notepad)\n##### For notepad\n```\ngit config --global core.editor notepad\n```\n\n##### For notepad++\nx64\n```git\ngit config --global core.editor \"'C:/Program Files/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin\"\n```\nx86\n```git\ngit config --global core.editor \"'C:/Program Files (x86)/Notepad++/notepad++.exe' -multiInst -notabbar -nosession -noPlugin\"\n```\n##### For sublime\nx64\n```git\ngit config --global core.editor \"'C:/Program Files/sublime text 3/subl.exe' -w\"\n```\nx86\n```git\ngit config --global core.editor \"'C:/Program Files (x86)/sublime text 3/subl.exe' -w\"\n```\n\n## Delete a branch\n```git\ngit checkout master\ngit push --delete origin branch_Name\ngit branch -D branch_Name\n```\n## Copy current branch to a new branch\n```git\ngit checkout -b new_Branch_Name\n```\n## Squash commits (merge)\nuse the commit ID of one commit before your first commit,\n```git\ngit rebase --interactive 0ca4f4376f04eee6599a4b2e17255357fb888422\n```\nWhen editor is opened,\nreplace pick which squash,\nmake the first squash pick again. (All other commits will be merged to this one)\nSave and close the first editor,\nthe second editor will be opened for editing comments.\nUse the first line and some enters after that as the title.\nWrite your comments below that (things after # are ignored)\nIn the end:\n```git\ngit push --force\n```\nAlternative method with number (not much useful)\n```git\ngit rebase --interactive HEAD~[53]\n```\n## Reword last commit's comment\n```git\ngit commit --amend -m \"title\" -m \"\n\nYour comment here\nuse enter for different lines\n\n\"\n```\n```git\ngit push --force\n```\n## Merge branch to master\n```git\ngit checkout master\ngit merge other_Branch\ngit push --force\n```\n## Remove last commit\nuse the id one before that\n```git\ngit reset --hard e78df3ad58a71eca510a76b716404841d6d4fe20\ngit push --force\n```\nor\n```git\ngit reset --hard HEAD^\ngit push origin -f\n```\n\n## Rename branch:\n```\ngit checkout old_name\ngit branch -m new_name\ngit push origin --delete old_name\ngit push origin -u new_name\n```\n\n## Rename a file:\nOpen the git bash in the folder that file exits (hold shift and right click and select open bash here on Windows)\n```git\ngit mv old_filename new_filename\n```\n\n## Fork Forced Sync\n```git\ngit fetch upstream\ngit reset --hard upstream/master\ngit push -f\n```\n\n## Move commits between branches\n```git\ngit checkout newbranch\ngit cherry-pick 87ea90d1~1..b4167564   # or: git cherry-pick \u003csha_of_one_commit_before\u003e..\u003csha_of_last_commit\u003e\n```\n```\nor\n```git\ngit cherry-pick d198f1d\n```\nDon't forget `~1`\n\n## Edit a deep commit\n- Save and stash your work so far, like before and commit what you have without amend mode: `git commit -a -m \"Foo\"`\n- From git log copy commit ID (SHA) of the one commit before the old commit onto your clipboard.\n- Start the interactive rebase process, pasting in the characters from the ID:\n```\ngit rebase --interactive ID\n```\n- Your editor will come up with several lines like `pick d3adb33` Commit message, one line for each commit since the older one.\nFor the most recent commit, change the word \"pick\" to \"squash\" at the start of the line. (This tells Git to combine it back into the one before it.)\n- Use your editor to reorder the lines, putting the line for the most recent commit just after the older commit you want to fix.\nSave and quit your editor.\n- The editor will come up again, this time asking you for the commit message for the combined commit. Delete or comment out the newer, temp message (\"Foo\").\n- Save and quit your editor, and:\n```\ngit push --force\n```\n\n## Sub-modules\n\n### Add a submodule to a repository\nCreate a .gitmodule in the repo\n\nthen use this git command\n```\ngit submodule add git@github.com:url_to/awesome_submodule.git path_to_submodule\n```\n\n### Add a submodule to a repository that follows a branch\nCreate a .gitmodule in the repo, then:\n```\ngit submodule add -b branch_name URL_to_Git_repo optional_directory_rename\ngit submodule update --remote\n```\n\n\n### Download (Initialize) the submodule:\n\nusing git commands:\n```git\ngit submodule update --init --recursive\n```\n\n### Update the submodule (if that repository changes):\n\nusing git commands:\n```git\ngit submodule update --remote --merge\n```\n\n\n### Delete a submodule\n```\ngit rm the_submodule_path\n```\n\nDelete .git/modules/the_submodule_path (using a command or manually)\nbash:\n```\nrm -rf .git/modules/the_submodule_path\n```\npwsh:\n```\nrm -r -force .git/modules/the_submodule\n```\n\n\nFor example, if we have libgit2 in deps/libgit2:\n```\ngit rm deps/libgit2\nrm -r -force .git/modules/libgit2\n```\n\n### Remove trailing whitespace\nGit solution:\n```git\ngit grep -I --name-only -z -e '' | xargs -0 sed -i 's/[ \\t]\\+\\(\\r\\?\\)$/\\1/'\n```\n\nGeneric solution:\n```sh\nwhile IFS= read -r -d '' -u 9\ndo\n    if [[ \"$(file -bs --mime-type -- \"$REPLY\")\" = text/* ]]\n    then\n        sed -i 's/[ \\t]\\+\\(\\r\\?\\)$/\\1/' -- \"$REPLY\"\n    else\n        echo \"Skipping $REPLY\" \u003e\u00262\n    fi\ndone 9\u003c \u003c(find . -type f -print0)\n```\n\n### Clone a branch\n```\ngit clone --single-branch --branch branchName repoMainURL\n```\n\n### Clone a subset of the branch\n\nUse this command to clone a huge repository. The depth indicates the recent commits you need.\n\n```\ngit clone --depth 2 --single-branch --branch branchName repoMainURL\n```\n\n### Clean a git repo from the untracked files\n\n:warning: Add `--dry-run` to preview and have a backup!\n\n- clean untracked files: \t`git clean -f`\n- remove untracked directories: `git clean -f -d`\n- remove ignored files: `git clean -f -X`\n- remove ignored as well as non-ignored files `git clean -f -x`\n\n### Clean a git repo from the old things/garbage/etc\n\n:warning: have a backup!\n\n```\ngit remote prune origin\ngit repack\ngit prune-packed\ngit reflog expire --expire=\"1 hour\" --all\ngit reflog expire --expire-unreachable=\"1 hour\" --all\ngit prune --expire=\"1 hour\" -v\ngit gc --aggressive --prune=\"1 hour\"\n```\n\n### Remove merged branches locally:\n```ps1\nfunction git-rm-merged\n{\n  git branch --merged |\n    ForEach-Object { $_.Trim() } |\n    Where-Object {$_ -NotMatch \"^\\*\"} |\n    Where-Object {-not ( $_ -Like \"*master\" )} |\n    ForEach-Object { git branch -d $_ }\n}\n```\n\n### Rewrite history to delete files\n:warning: Have a backup!\n\nPowerShell\n```ps1\n$paths = \"path1\", \"path2\", \"path3\"\n\nforeach ($path in $paths) {\n   git filter-repo --invert-paths --path $path\n   if (test-path $path) {\n      rm $path -Recurse -Force\n   }\n   git reflog expire --expire=now --all \u0026\u0026 git gc --prune=now --aggressive\n}\n```\n\nPush the changes:\n```\ngit remote add origin git@github.com:YourUserName/YourRepoName.git\ngit push --set-upstream origin master -f\ngit push --force --all origin\n```\n\n### Change upstream url\n```\ngit rm upstream\ngit add upstream new_url\n```\n","funding_links":["https://github.com/sponsors/aminya","https://polar.sh/aminya","https://patreon.com/aminya"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminya%2Facutegit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faminya%2Facutegit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faminya%2Facutegit/lists"}