{"id":25005201,"url":"https://github.com/foyez/git","last_synced_at":"2025-03-29T22:42:53.717Z","repository":{"id":116061989,"uuid":"356786444","full_name":"foyez/git","owner":"foyez","description":"Git at a glance","archived":false,"fork":false,"pushed_at":"2024-02-21T14:13:10.000Z","size":19,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-05T00:29:55.097Z","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/foyez.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}},"created_at":"2021-04-11T06:31:27.000Z","updated_at":"2024-01-28T15:18:56.000Z","dependencies_parsed_at":"2024-02-21T15:49:22.044Z","dependency_job_id":"ba3ddff3-7d7c-4179-aefb-7c25e5516f84","html_url":"https://github.com/foyez/git","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/foyez%2Fgit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foyez%2Fgit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foyez%2Fgit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foyez%2Fgit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foyez","download_url":"https://codeload.github.com/foyez/git/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246254100,"owners_count":20747948,"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":"2025-02-05T00:30:03.087Z","updated_at":"2025-03-29T22:42:53.695Z","avatar_url":"https://github.com/foyez.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git\n\n## Check Git configuration:\n\n```bash\ngit config -l\n```\n\n## Git configuration:\n\n```bash\n# setup user info globally\ngit config --global user.name \"username\"\ngit config --global user.email \"username@email.com\"\n\n# setup user info locally (specific git repository)\ngit config user.name \"username\"\ngit config user.email \"username@email.com\"\n\n# edit global git configuration\ngit config --global --edit \n\n# set default branch name of git initialization\ngit config --global init.defaultBranch \u003cname\u003e\n```\n\n## Cache Login credential:\n\n```bash\ngit config --global credential.helper cache\n```\n\n## Initialize git\n\n```bash\ngit init\n```\n\n## Stage files\n\n```bash\ngit add file_name # add a file\ngit add * # add all files\ngit add fil* # add all files starting with 'fil'\n```\n\n## Check repository status\n\n```bash\ngit status\n```\n\n## Commit changes\n\n```bash\ngit commit # commit in editor\ngit commit -m \"your message\" # commit with message\ngit commit -am \"your message\" # add \u0026 commit tracked files\n```\n\n## Commit history\n\n```bash\ngit log # see commit history\ngit log -p # see commit history including changes\ngit log --stat # see commit history including line(s) changed and file names\ngit log --graph --oneline # show log graph of a branch\ngit log --graph --oneline --all # show log graph of all branches\n```\n\n## See changes made before committing\n\n```bash\ngit diff # all unstaged changes\ngit diff file_name # unstaged changes of a specific file\ngit diff --staged\n```\n\n## Remove tracked files\n\n```bash\ngit rm filename\n```\n\n## Remove tacked files/directories that was tracked already\n\n```bash\ngit rm --cached \u003cfile\u003e\ngit rm -r --cached \u003cfolder\u003e # for directory\n```\n\n## Rename files\n\n```bash\ngit mv old_file new_file\n```\n\n## Revert unstaged changes\n\n```bash\ngit checkout filename # revert unstaged changes from specified file\ngit checkout -- . # revert unstaged changes from all files\n```\n\n## Revert staged changes\n\n```bash\ngit reset HEAD filename\ngit reset HEAD~2 # revert the last two commits\ngit reset --hard HEAD~1 # revert the last commit and discard the changes\ngit reset HEAD -p # specify the changes you want to reset\n```\n\n## Amend the most recent commit\n\n```bash\n# should avoid amending pushed commits\ngit commit --amend # modify and add changes to the most recent commit\ngit commit --amend -m \"your message\"\n```\n\n## Undo last commit\n\n```bash\ngit reset HEAD~\nor \ngit reset HEAD~1\n```\n\n## Rollback an old commit\n\n```bash\ngit revert commit_id # create a new commit to revert the old changes\n```\n\n## Create \u0026 switch branch\n\n```bash\ngit branch branch_name\ngit checkout -b branch_name # create a new brach \u0026 switch to new created branch\ngit checkout branch_name\n```\n\n## Show branch list\n\n```bash\ngit branch\n```\n\n## Rename a branch\n\n```bash\ngit branch -M \u003cname\u003e\n```\n\n## Delete a branch locally \u0026 remotely\n\nDelete a local branch:\n\n```bash\ngit branch -d \u003cbranch_name\u003e\n```\n\nDelete a remote branch:\n\n```bash\ngit push \u003cremote_name\u003e -d \u003cbranch_name\u003e # remote_name is normally origin\n```\n\n## Switch branch \u0026 keep changes\n\n1. switch with creating new branch\n```bash\ngit switch -c \"new_branch_name\"\n```\n\n2. switch without creating new branch\n```bash\ngit stash save\ngit checkout branch\ngit stash pop\n```\n\n## Merge two branches\n\n```bash\ngit merge branch_name # merge active branch with branch_name\ngit merge --abort # abort a conflicting merge\n```\n\n## Add a remote repository\n\n```bash\ngit add remote remote_repo_url\n```\n\n## See remote URLs\n\n```bash\ngit remote -v\ngit remote show origin # get more info about remote repo\n```\n\n## Interact with remote repo\n\n```bash\ngit push -u origin branch_name # push a new branch to a remote repo\ngit push # push changes to a remote repo\ngit push -f # force a push request\ngit fetch # download the latest changes from a remote repo\ngit pull # download the latest changes from a remote repo and merge them with local branch\ngit pull -r # download the latest changes from a remote repo and rebase them with local branch\ngit branch -r # check remote branches\n```\n\n## Resolve a conflict\n\n```bash\ngit pull -r\n# Resolve conflicts which changes you want to add\ngit add .\ngit rebase --continue\n```\n\n## Git rebase (transfer completed work from one branch to another)\n\n```bash\ngit rebase branch_name\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoyez%2Fgit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoyez%2Fgit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoyez%2Fgit/lists"}