{"id":23335019,"url":"https://github.com/workwithafridi/git-tips-tricks","last_synced_at":"2025-04-09T19:41:10.055Z","repository":{"id":152118535,"uuid":"622804557","full_name":"WorkWithAfridi/Git-Tips-Tricks","owner":"WorkWithAfridi","description":"A repo consisting some of the most used git commands and their description/ shortcuts.","archived":false,"fork":false,"pushed_at":"2024-05-07T15:44:34.000Z","size":15,"stargazers_count":6,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T21:35:48.441Z","etag":null,"topics":["git"],"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/WorkWithAfridi.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-04-03T05:16:24.000Z","updated_at":"2024-07-01T04:39:52.000Z","dependencies_parsed_at":"2024-05-07T16:47:32.373Z","dependency_job_id":"f249fb81-376d-415b-ad06-5ea1407338da","html_url":"https://github.com/WorkWithAfridi/Git-Tips-Tricks","commit_stats":null,"previous_names":["workwithafridi/git-tips-tricks"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WorkWithAfridi%2FGit-Tips-Tricks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WorkWithAfridi%2FGit-Tips-Tricks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WorkWithAfridi%2FGit-Tips-Tricks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WorkWithAfridi%2FGit-Tips-Tricks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WorkWithAfridi","download_url":"https://codeload.github.com/WorkWithAfridi/Git-Tips-Tricks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248100324,"owners_count":21047778,"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"],"created_at":"2024-12-21T01:15:27.313Z","updated_at":"2025-04-09T19:41:10.039Z","avatar_url":"https://github.com/WorkWithAfridi.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"Git Commands\n============\n\n### Getting \u0026 Creating Projects\n\n| Command | Description |\n| ------- | ----------- |\n| `git init` | Initialize a local Git repository |\n| `git clone ssh://git@github.com/[username]/[repository-name].git` | Create a local copy of a remote repository |\n\n### Basic Snapshotting\n\n| Command | Description |\n| ------- | ----------- |\n| `git status` | Check status |\n| `git add [file-name.txt]` | Add a file to the staging area |\n| `git add -A` | Add all new and changed files to the staging area |\n| `git commit -m \"[commit message]\"` | Commit changes |\n| `git rm -r [file-name.txt]` | Remove a file (or folder) |\n| `git reset head --hard` | Resets local repo to last commit/head - will lose all the changes |\n| `git reset --soft HEAD~` | Resets local repo's current (n) commit to n-1 commit - without losing the nth committed changes |\n| `git stash` | To store current changes without commiting |\n| `git pop` | To bring back the stashed changes |\n| `git clean -df` | To delete unwanted untracked files |\n| `git checkout -` | To move to previous branch after checking out new branch |\n\n### Branching \u0026 Merging\n\n| Command | Description |\n| ------- | ----------- |\n| `git branch` | List branches (the asterisk denotes the current branch) |\n| `git clone --branch 11.5 --shallow-since=3m https://github.com/MariaDB/server.git mariadb-serverh` | This will make a clone that only tracks branch 11.5 and no other branches. Additionally this uses the shallow clone feature to fetch commit history only for the past 3 months instead of the entire history (which in this example otherwise would be 20+ years). |\n| `git branch -a` | List all branches (local and remote) |\n| `git branch [branch name]` | Create a new branch |\n| `git branch -d [branch name]` | Delete a branch |\n| `git push origin --delete [branch name]` | Delete a remote branch |\n| `git checkout -b [branch name]` | Create a new branch and switch to it |\n| `git checkout -b [branch name] origin/[branch name]` | Clone a remote branch and switch to it |\n| `git branch -m [old branch name] [new branch name]` | Rename a local branch |\n| `git checkout [branch name]` | Switch to a branch |\n| `git checkout -` | Switch to the branch last checked out |\n| `git checkout -- [file-name.txt]` | Discard changes to a file |\n| `git merge [branch name]` | Merge a branch into the active branch |\n| `git merge [source branch] [target branch]` | Merge a branch into a target branch |\n| `git stash` | Stash changes in a dirty working directory |\n| `git stash clear` | Remove all stashed entries |\n| `git reset --hard origin/master` | To override local git with that of the remote. This will reset everything to match the remote |\n\n### Sharing \u0026 Updating Projects\n\n| Command | Description |\n| ------- | ----------- |\n| `git config --local fetch.prune true` | Removes and cleans up repo, deletes branchs which are also removed/deleted from the remote repos |\n| `git push origin [branch name]` | Push a branch to your remote repository |\n| `git push -u origin [branch name]` | Push changes to remote repository (and remember the branch) |\n| `git push` | Push changes to remote repository (remembered branch) |\n| `git push origin --delete [branch name]` | Delete a remote branch |\n| `git pull` | Update local repository to the newest commit |\n| `git pull origin [branch name]` | Pull changes from remote repository |\n| `git remote add origin ssh://git@github.com/[username]/[repository-name].git` | Add a remote repository |\n| `git remote set-url origin ssh://git@github.com/[username]/[repository-name].git` | Set a repository's origin branch to SSH |\n| `git remote update` | will fetch all remotes and make sure you have all the latest git commits made since the last time you worked with the repository |\n\n### Inspection \u0026 Comparison\n\n| Command | Description |\n| ------- | ----------- |\n| `git log` | View changes |\n| `git log --summary` | View changes (detailed) |\n| `git log --oneline` | View changes (briefly) |\n| `git diff [source branch] [target branch]` | Preview changes before merging |\n| `git log --graph --oneline --decorate` | To log commits in a graph like form |\n\n### Remove Git\n\n| Command | Description |\n| ------- | ----------- |\n| `rm -rf .git` | Removes GIT from current working repo |\n\n### Git Shortcuts\n\n| Command | Description |\n| ------- | ----------- |\n| `git commit -am\"Your commit message\"` | Instead of git add . \u0026 git commit -m\"Your commit message\" |\n| `git config --global alias.\u003c\u003cYour shortcut here\u003e\u003e \"\u003c\u003cgit command here\u003e\u003e\"` | Adds a custom command. For Example: `git config --global alias.ac \"commit -am\"`, sets \"git ac\" as git commit -am. | \n| `git commit --amend -m\"\u003c\u003cYour commit message\u003e\u003e\"` | Will updated the last commit message |\n| `git push origin YOURBranch --force` | Will override the remote repo with local repo |\n| `git revert --no-commit 0d1d7fc3..HEAD -\u003e git commit` | Revert to a previous published commit |\n\n### Replace Git History with new Author\n\n| Command | Description |\n| ------- | ----------- |\n| `git filter-branch -f --env-filter \" GIT_AUTHOR_NAME='WorkWithAfridi' GIT_AUTHOR_EMAIL='afridi.khondakar@gmail.com' GIT_COMMITTER_NAME='WorkWithAfridi' GIT_COMMITTER_EMAIL='afridi.khondakar@gmail.com' \" HEAD` | Run the script to replace past commit's author history with new author |\n\n ```\ngit filter-branch -f --commit-filter '\n    if [ \"$GIT_AUTHOR_NAME\" = \"old_username\" ] \u0026\u0026 [ \"$GIT_AUTHOR_EMAIL\" = \"old_email\" ]; then\n        GIT_AUTHOR_NAME=\"WorkWithAfridi\"\n        GIT_AUTHOR_EMAIL=\"afridi.khondakar@gmail.com\"\n        GIT_COMMITTER_NAME=\"WorkWithAfridi\"\n        GIT_COMMITTER_EMAIL=\"afridi.khondakar@gmail.com\"\n    fi\n    git commit-tree \"$@\"\n' HEAD \n```\n- Run the script to replace certain users commit's author history with new author, remember to change the old_username \u0026 old_email properties |\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkwithafridi%2Fgit-tips-tricks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkwithafridi%2Fgit-tips-tricks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkwithafridi%2Fgit-tips-tricks/lists"}