{"id":21343162,"url":"https://github.com/rancorm/git-questions","last_synced_at":"2026-05-19T03:20:55.305Z","repository":{"id":191923161,"uuid":"685652431","full_name":"rancorm/git-questions","owner":"rancorm","description":"An extensive collection of meticulously curated Git questions and answers","archived":false,"fork":false,"pushed_at":"2024-04-22T00:42:31.000Z","size":211,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-16T03:13:03.054Z","etag":null,"topics":["developer-tools","development","git","git-questions"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rancorm.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-31T17:47:09.000Z","updated_at":"2024-04-22T00:42:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"f77c2743-ed29-47f7-ac62-be671f3bf78f","html_url":"https://github.com/rancorm/git-questions","commit_stats":null,"previous_names":["jcormir/git-questions","rancorm/git-questions"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rancorm/git-questions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancorm%2Fgit-questions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancorm%2Fgit-questions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancorm%2Fgit-questions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancorm%2Fgit-questions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rancorm","download_url":"https://codeload.github.com/rancorm/git-questions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rancorm%2Fgit-questions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267320259,"owners_count":24068527,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["developer-tools","development","git","git-questions"],"created_at":"2024-11-22T01:12:15.269Z","updated_at":"2026-05-19T03:20:55.264Z","avatar_url":"https://github.com/rancorm.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Git Questions\n\n![Cover Image](cover.jpg)\n\nIllustration by [Muhammad Ribkhan](https://www.vecteezy.com/members/khan-zein554159)\n\n---\n\nAn extensive collection of meticulously curated Git questions and answers. Concepts like branching, merging, and committing to advanced topics such as rebasing, cherry-picking, and submodules, we've got you covered.\n\n## Contribute\n\nPull requests are welcome.\n\n## Table of Contents\n\n- [Setting Up](#setting-up)\n- [Basics](#basics)\n- [Branch \u0026 Merge](#branch--merge)\n- [Workflow](#workflow) \n- [Collaboration \u0026 Remote Repositories](#collaboration--remote-repositories)\n- [Advanced Topics](#advanced-topics)\n- [Best Practices](#best-practices)\n- [Tools \u0026 Extensions](#tools--extensions)\n- [Tips \u0026 Troubleshooting](#tips--troubleshooting)\n- [Continuous Integration \u0026 Deployment](#continuous-integration--deployment)\n- [Security \u0026 Access Control](#security--access-control)\n\n## Setting Up\n\nTo make copy and pasting easier, set the environment variable `GQ_URL` and friends to their respective\nvalues.\n\nExample:\n\n```sh\nexport GQ_URL=https://github.com/jcormir/git-questions.git\nexport GQ_BRANCH=awesome-branch\nexport GQ_TAG=v1.0\nexport GQ_COMMIT=c8e491e\nexport GQ_REPO=git-questions\nexport GQ_FILE=file.txt\nexport GQ_DIR=a_directory/\n```\n\n\n## Basics\n\nSetup new repostories, clone existing ones, and just getting to know Git.\n\n### Create a new repository\n\nCreate an empty Git repository or reinitialize an existing one.\n\n```sh\ngit init $GQ_REPO\n```\n\nRunning `git init` in an existing repository is safe. It will not overwrite things that\nare already there.\n\n### Clone existing repository\n\nTo clone an already existing repository.\n\n```sh\ngit clone $GQ_URL\n```\n\n### Ignore files\n\nThe repository file `.gitignore` is a configuration file used in Git repositories to specify\nfiles and directories that should be excluded from version control.\n\nExample that excludes C objects (.o), Python compiled bytecode (.pyc), and directory named `build`.\n\n```sh\n*.pyc\n*.o\nbuild/\n```\n\nHead to [gitignore.io](https://www.toptal.com/developers/gitignore/) to get `.gitignore` entries for your project.\n\n## Branch \u0026 Merge\n\nWhether you're working by yourself or on a team, you should have a repository work flow\nthat involves merging branches. Feature branches, long term release branches, etc.\n\n### Make a branch\n\nNew local branch based on `HEAD`.\n\n```sh\ngit branch $GQ_BRANCH\n```\n\n### Switch repository branch\n\nSwitch repository branch.\n\n```sh\ngit switch $GQ_BRANCH\n```\n\nShortcut to create and switch to a branch in a single command.\n\n```sh\ngit switch -c $GQ_BRANCH\n```\n\n### Branch from an existing branch\n\nNew local branch from existing branch.\n\n```sh\ngit branch $GQ_BRANCH \u003cbase-branch\u003e\n```\n\n### Branch from a specific commit or tag\n\nIf you want to start your new local branch based on a specific commit or tag, then\nyou can provide the commit hash or tag name as the starting point.\n\n```sh\ngit branch $GQ_BRANCH $GQ_COMMIT\n```\n\n### Push local branch to remote repository\n\nAfter working on your new local branch for some time, you might want to publish it in your\nremote repository, to share it with your team:\n\n```sh\ngit push -u origin $GQ_BRANCH\n```\n\nThe `-u` or `--set-upstream` tells Git to establish a tracking reference, which argument-less\n**git-pull** and other commands make use.\n\n### What branches have or have not merged\n\nTo get a list of branches that have been merged into the current branch.\n\n```sh\ngit branch --merged $GQ_COMMIT\n```\n\nTo get a list of branches that have not been merged use `--no-merged`.\n\n### Merge branch\n\nTo merge changes from another branch into the current branch.\n\n```sh\ngit merge $GQ_BRANCH\n```\n\nIf you would like to keep the repository history clean of the commits from the merging\nbranch, you can use the `--squash` argument to squash the commits to a single commit and\nstage. Allowing for commit message and merge conflict changes.\n\n```sh\ngit merge --squash $GQ_BRANCH\n```\n\nWhen done [push](#update-a-remote-repository) the changes to the remote.\n\n\n## Tags\n\n### Add annotated tag\n\nAnnotated tags are stored as objects in the repository. They’re checksummed; contain the tagger name,\nemail, and date; have a message; and can be signed and verified.\n\nIt’s recommended to create annotated tags to have this information; but if you want a temporary tag,\nlightweight tags are available too.\n\n```sh\ngit tag -a v1.0 -m \"Version 1.0\"\n```\n\n### List tags\n\nSearch for tags that match a particular pattern. If you’re interested only in looking at the 1.0 release\ntags, run this:\n\n```sh\n$ git tag -l \"v1.*\"\n```\n\n\n## Workflow\n\nCommands you will use throughout the development day.\n\n### Stage file or changes for commit\n\nTo track a file or add changes that are yet apart of a commit.\n\n```sh\ngit add $GQ_FILE\n```\n\n### Unstage a file or directory\n\nIf you need to remove a file from the staging area without removing to local file, maybe\nyou `git add` a file by accident and need to remove it.\n\n```sh\ngit reset HEAD -- $GQ_FILE\n```\n\nIf you need to remove a directory from the staging area.\n\n```sh\ngit reset HEAD -- $GQ_DIR\n```\n\nYour changes will be kept. When you run `git status` the file will once again show up as\nmodified but not yet staged.\n\n### What revision last modified a line of a file\n\nIf you're looking for the revision and author that last modified each line of a\nfile, the `git blame` command does exactly that.\n\n```sh\ngit blame\n```\n\nIf you would like to limit the output to a line range use the `-L` argument.\n\n```sh\ngit blame -L 26,28\n```\n\nOther useful options to the `git blame` command. To ignore whitespace include `-w`, which\na lot of web UI don't do by default. To detect lines moved or copied in the same commit\ninclude `-C`, or in the commit that created the file and another `-C`, or in any commit\nat all include another `-C`.\n\n```\ngit blame -w -CCC\n```\n\n### Show me the differences\n\nTo view the changes that are yet to be staged, use the `git diff` command with no switches.\n\n```\ngit diff\n```\n\nIf you already staged your changes, you can view those changes by adding `--cached` switch.\n\n```\ngit diff --cached\n```\n\nIf you want to diff on words vs lines you can by adding `--word-diff` switch.\n\n```\ngit diff --word-diff\n```\n\n### Looking through repository history\n\nTo pick through the repository commit history use `git log`.\n\nList commits that are reachable by following the parent from the given commit(s), but\nexclude commits that are reachable from the one(s) with a prefix of `^`.\n\n```sh\ngit log\n```\n\nThe output is given in reverse chronological order.\n\n```sh\ncommit 0113f8d73745c3cda3a32360772f6055828012d3 (HEAD -\u003e main, origin/main, origin/HEAD)\nAuthor: Jonathan Cormier \u003cjonathan@example.net\u003e\nDate:   Sun Sep 3 22:05:35 2023 -0300\n```\n\nIf you want basic one line commit descriptions you can use `--oneline` argument.\n\nTo narrow the output a special notation `\u003ccommit1\u003e..\u003ccommit2\u003e` can be used as a short-hand\nfor `^\u003ccommit1\u003e \u003ccommit2\u003e`. For example, either of the following may be used interchangeably:\n\n```sh\ngit log origin..HEAD\ngit log HEAD ^origin\n```\n\n`HEAD` is a reference to the latest commit in the repository.\n\n### Searching through repository history\n\nIf you would like to search through the repository log, you can use `git log -S` and\nsuppy it a regular expression for filtering.\n\n```\ngit log -S $GQ_REGEXP\n```\n\nIf you want to see the revisions include the `-p` switch.\n\n### Commit changes\n\nOnce you have your changes staged for commit using `git add`. You need to commit.\n\n```sh\ngit commit -m \"Message\"\n```\n\nYou can make multiple commits before you push them to a remote, if the situation\ncalls for it. If you have too many commits you can squash them to keep the repository\nhistory clean.\n\n### Show the working status\n\nTo see what changes are staged for commit, untracked files, etc. Git `status` is where you\nwill find that information.\n\n```sh\ngit status -s\n```\n\n Use the `-s` argument for short output with just change type (M, ??) and filename.\n\n### Stash working directory and index changes\n\nIf you would like to stash the current working directory and index changes to work on later or\ncommit at a later time. Use the `git stash` command to bring the repository back to `HEAD`.\n\n```sh\ngit stash\n```\n\nThis can be done multiple times, if you want to make changes and stash those you can. List the\ncurrent stashes.\n\n```sh\ngit stash list\n```\n\nInclude the switch `--all` to include untracked files.\n\n### Restoring stash changes\n\nRestore top stash by applying it to the current working directory and then removing it.\n\n```sh\ngit stash pop\n```\n\n\n## Collaboration \u0026 Remote Repositories\n\n### Pull changes\n\nPull changes and merge remote repository or local branch.\n\n```sh\ngit pull\n```\n\n### Fetch changes\n\nFetch changes from remote repository but don't merge them.\n\n```sh\ngit fetch\n```\n\n### Update a remote repository\n\nTo have your changes available through remotes, push them.\n\n```sh\ngit push\n```\n\n### List remote repositories\n\nTo list the set of repositories and their location.\n\n```sh\ngit remote -v\n```\n\n### Change remote location\n\nChange the URL of a remote repository.\n\n```sh\ngit remote set-url origin $GQ_NEW_URL\n```\n\n\n## Advanced Topics\n\nRebasing, cherry-picking, and managing submodules.\n\n### Clone repository recursively\n\nClone a repository and submodules. *2.13+*\n\n```sh\ngit clone --recurse-submodules $GQ_URL\n```\n\nPerformance optimization that is available in *2.8* to set the number of submodules to fetch at\nthe same time use `-j` or `--jobs`. Defaults to the `submodule.fetchJobs` option.\n\n```sh\ngit clone --recurse-submodules -j8 $GQ_URL\n```\n\n### List of untracked files in working tree\n\nFiles that are not in the index and outside .gitignore rules. \n\n```sh\n git ls-files -o --exclude-standard\n```\n\n### Show current configuration with scope\n\nTo display the current git configuration with scope details.\n\n```sh\ngit config -l --show-scope | cat\n```\n\n### Remove untracked files\n\nTo remove all untracked files in a repository, you can use the following command:\n\n```sh\ngit clean -fd\n```\n\n\n## Best Practices\n\n- Commit messages should being with a short description of 50 character limit on the first line. Followed\nby a single blank line with each following line a description of the changes in the commit.\n- Always pull before a push to make sure you will not face any rejections from Git.\n- Always pull from related branches before you start new work on your code. It will keep your\nbranch up-to-date and reduce the chances of conflicts.\n\n\n\n## Tools \u0026 Extensions\n\n- [Meld](https://meldmerge.org)\n- [GitHub Desktop](https://desktop.github.com)\n- [Magit](https://magit.vc)\n- [git-interactive-rebase-tool](https://github.com/MitMaro/git-interactive-rebase-tool)\n- [Lazygit](https://github.com/jesseduffield/lazygit)\n\n## Tips \u0026 Troubleshooting\n\n### Change conflict style\n\nChange conflict style to zealous diff3, `zdiff3`.\n\n```ini\nmerge.conflictStyle = zdiff3\n```\n\n### Make and use aliases\n\nTo make multiple step dependent tasks easier, turn them into aliases or scripts called by and alias. For example,\nthe script [update-repos.sh](/scripts/update-repos.sh) can be used to perform a pull on multiple directores. Make an alias for convenience.\n\n```ini\nalias.update-repos = '!update-repos.sh'\n```\n\n```bash\n$ git update-repos\nPull for ./git-questions...\n```\n\n\n## Continuous Integration \u0026 Deployment\n\nShallow clones aren't recommended for developers.\n\n### Shallow clone\n\nPerform a shallow clone when the repository history isn't a requirement and the clone with be\ndiscarded.\n\n```sh\ngit clone --depth=1 $GQ_URL\n```\n\n### Shallow clone a specific branch\n\nPerform the same shallow only on a specific branch.\n\n```sh\ngit clone --depth=1 --single-branch --branch=$GQ_BRANCH $GQ_URL\n```\n\n\n## Security \u0026 Access Control\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Francorm%2Fgit-questions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Francorm%2Fgit-questions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Francorm%2Fgit-questions/lists"}