{"id":18265824,"url":"https://github.com/mbianchidev/git-aliases","last_synced_at":"2025-04-09T01:45:55.895Z","repository":{"id":182175275,"uuid":"668064663","full_name":"mbianchidev/git-aliases","owner":"mbianchidev","description":"My personal git wiki","archived":false,"fork":false,"pushed_at":"2024-08-23T15:09:57.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T20:32:04.531Z","etag":null,"topics":["cli","git"],"latest_commit_sha":null,"homepage":"","language":"Shell","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/mbianchidev.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":"2023-07-19T00:20:15.000Z","updated_at":"2024-08-23T15:10:01.000Z","dependencies_parsed_at":"2024-08-23T16:53:44.134Z","dependency_job_id":null,"html_url":"https://github.com/mbianchidev/git-aliases","commit_stats":null,"previous_names":["mbianchidev/git-aliases"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbianchidev%2Fgit-aliases","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbianchidev%2Fgit-aliases/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbianchidev%2Fgit-aliases/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbianchidev%2Fgit-aliases/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbianchidev","download_url":"https://codeload.github.com/mbianchidev/git-aliases/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247958708,"owners_count":21024827,"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":["cli","git"],"created_at":"2024-11-05T11:20:02.306Z","updated_at":"2025-04-09T01:45:55.862Z","avatar_url":"https://github.com/mbianchidev.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# mbianchidev's Git Wiki\n\nYou can find the official Git CLI doc here: https://git-scm.com/docs/git\nThis was a set of notes I took while learning Git some years ago. I hope it helps you too.\nThere might be some errors and it might get outdated in time, so please let me know if you find any mistake and I'll fix it. PRs are welcome too.\n\n## Setting up aliases\n\nRun the git-aliases.sh script (curl or wget required) example uses curl, wget runs with different parameters.\n\n```bash\n/bin/bash -c \"$(curl -fsSL https://raw.githubusercontent.com/mbianchidev/git-aliases/main/git-aliases.sh)\"\n```\n\nor\n\nDownload the gitconfig file and edit it to your needs, then copy it to your git config folder. \n\nWin usual location is `C:/Program Files/Git/etc/gitconfig`, while Linux/Mac usual location is `$HOME/.gitconfig`\n\n```bash\n/bin/bash -c \"$(wget -O- https://raw.githubusercontent.com/mbianchidev/git-aliases/main/.gitconfig)\" \u0026\u0026 vim .gitconfig\n```\n\n## Cloning a repository\n\n```bash\n# clone the repository to the chosen destination folder\ngit clone https://user:pass@[git-provider]/group/repo.git example/\ngit clone ssh://[git-provider]/user/repo.git\n# including all submodules\ngit clone --recurse-submodules https://user:pass@[git-provider]/group/repo.git example/\n```\n\n## Pulling changes\n\n```bash\n# fetch remote changes and merge them into the current branch\ngit pull\n# fetch remote changes and rebase the current branch on top of them\ngit pull --rebase\n```\n\n## Branching\n\n```bash\n# create a new \"example\" local branch\ngit branch example\n# create a new \"example\" local branch and switch to it\ngit checkout -b example\n# push local branch to remote\ngit push origin example\n# Add remote branch to local\ngit remote add origin example\n# delete the remote branch\ngit push origin --delete example\n# delete the local branch\ngit branch -D example\n# show all remote branches\ngit branch -r\n# show all local branches\ngit branch\n\n## Renaming\n\n# switch branches\ngit checkout old\n# rename the local branch\t\t\t\ngit branch -m renamed\n# push the renamed branch to the remote\ngit push origin -u renamed\n# when you're sure, delete the old branch from the remote\ngit push origin --delete old \n```\n\n## Adding changes\n\n```bash\n# stage all files\ngit add .\n# stage files, excluding new files (and ofc .gitignore'd)\ngit add *\n# stage files, including new files\ngit add -A \n```\n\n## Commit changes\n\n```bash\n# commits all staged changes with the given message in the local branch\ngit commit -m \"Example message\"\n# commit with header and body\ngit commit -m \"Header\" -m \"Body\"\n```\n\n## Signing commits with GPG\n```bash\ngpg --gen-key # needs gpg installed\ngpg -K --keyid-format SHORT\ngit config --global user.signingKey \u003ctheID\u003e\ngit config--global commit.gpgsign true\n```\n\n## Signing commits with SSH\n```bash\ngit config --global user.signingKey $HOME/.ssh/id_3ru2r.pub\ngit config --global commit.gpgsign true\n```\n\n## Signing commits with a key\n```bash\ngit config --global push.autoSetupRemote true\n\n```\n\n## Push changes\n    \n```bash\n# If an upstream is set, push changes to remote branch\ngit push\n# If an upstream is not set, push changes to remote branch and set upstream\ngit push --set-upstream origin example\n```\n\n## Syncing (a fork)\n\n```bash\n# fetch remote changes\ngit fetch\n# fetch remote changes from upstream\ngit fetch upstream\n# merge remote changes from upstream (fork)\ngit merge upstream/main \n```\n\n## Reset or undo changes\n\n```bash\n# unstage all files\ngit reset . \t\t\t\t\n# unstage a specific file and revert it to the HEAD revision (latest pushed commit)\t\t\t\t\ngit reset HEAD -- path/to/file/to/revert.json\n# unstage all files and discard changes, reverting them to the HEAD revision\ngit reset --hard HEAD \n\n# Reverting last commit without losing it\n\n# undo last remote pushed commit\ngit reset HEAD~\n# undo last local commit and keep changes\ngit reset HEAD~1 --soft\n# same as above but with a specific commit\ngit reset HEAD~[commit number] --soft\n# unstage the specified file\ngit reset HEAD -- app/reset.java\n\n# reset the file to the HEAD (if not yet committed)\ngit checkout path/to/file/to/revert.ts\n# reset the file to the target branch\ngit checkout origin/my_branch -- file/example.jsx\n# reset all files to the HEAD (if not yet committed)\ngit checkout -- .\n\n```\n\n## Rebase\nhttps://git-scm.com/docs/git-rebase \nhttps://medium.freecodecamp.org/git-rebase-and-the-golden-rule-explained-70715eccc372 \n\n```bash\n# checkout the branch you want to be in sync with (usually main)\ngit checkout main\n# fetch changes from the remote\ngit pull --rebase\n# checkout the branch you want to rebase (usually development or feature ones)\ngit checkout my_feature\n# rebase the branch on top of the target branch\ngit rebase main\n# if there are conflicts, resolve them and continue the rebase or skip a commit, abort if you want to stop\ngit rebase --continue | --skip | --abort\n# check the status. Is your branch different from origin? It's okay, it should be.\ngit status\n# force push ONLY to your branch\ngit push -f \n```\n\n## Cleaning\n\n```bash\n# show what would be removed with clean\ngit clean -n\n# remove all untracked files\ngit clean -f\n# remove all untracked directories\ngit clean -d\n# remove untracked files and directories\ngit clean -(n)df\n```\n\n## Stashing\n\n```bash \n# temporarily stash changes\ngit stash \n# fetch new\t\ngit pull\n# apply the stashed changes again\ngit stash pop\n# drop the stashed changes\ngit stash drop \n```\n\n## Merge\n\n```bash\n# merge the main branch into the current branch\ngit merge main\n# abort or keep the merge\ngit merge --abort | --continue \n```\n\n## Cherry-picking\n\n```bash\n# cherry-pick a commit from another branch\ngit cherry-pick [commit hash]\n```\n\n## Remote\n\n```bash\n# show all remote names\ngit remote -v\n```\n\n# Rewriting history\n\n```bash\n# revert a range of commits (on the current branch, beware of conflicts)\ngit revert \u003cold_commit_hash\u003e..\u003clatest_commit_hash\u003e \u0026\u0026 git push -f\n```\n\n# Git magic squash when forking and working on a branch =/= main\n\n```bash\ngit reset --soft \"$(git merge-base main HEAD)\" )\" \u0026\u0026 git commit 'new message' \u0026\u0026 git push --force-with-lease\n```\n\n## Amend author in the whole repo\n    \n```bash\n\ngit filter-branch --env-filter '\nWRONG_EMAIL=\"yyy@ddd.dev\"\nNEW_NAME=\"John Doe\"\nNEW_EMAIL=\"John.Doe@gmail.com\"\n\nif [ \"$GIT_COMMITTER_EMAIL\" = \"$WRONG_EMAIL\" ]\nthen\n    export GIT_COMMITTER_NAME=\"$NEW_NAME\"\n    export GIT_COMMITTER_EMAIL=\"$NEW_EMAIL\"\nfi\nif [ \"$GIT_AUTHOR_EMAIL\" = \"$WRONG_EMAIL\" ]\nthen\n    export GIT_AUTHOR_NAME=\"$NEW_NAME\"\n    export GIT_AUTHOR_EMAIL=\"$NEW_EMAIL\"\nfi\n' --tag-name-filter cat -- --branches --tags\n```\n\n## Aliases\n    \n```bash\n# create an alias for the defined command\ngit config --global alias.\u003calias name\u003e '\u003ccommand\u003e' \n\n\n# Show aliases alias so you can run \"git alias\"\ngit config --global alias.alias \"! git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e s/\\ /\\ =\\ /\"\n```\n\n## Tagging\n\n```bash\n# show tags\ngit tag\n# show log on a single line per commit\t\t\t\t\t\t\t\t\t     \ngit log --pretty=oneline\n# tag a commit\ngit tag [tag name e.g., 2.17.3] [commit name]\n# push a tag\ngit push origin [tag name]\n# push all tags     \ngit push origin --tags\t\t\t\t     \n```\n\n## Check history\n\n```bash \n# commit history\ngit log\n# history with changes\ngit log -p\n# show only the latest commit\ngit log -1 \n\n## Magic log \n\ngit log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all\n\ngit log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all\n```\n\n## Finding bugs via git?\n\nSee: https://git-scm.com/docs/git-bisect\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbianchidev%2Fgit-aliases","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbianchidev%2Fgit-aliases","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbianchidev%2Fgit-aliases/lists"}