FAQ¶
Common questions and doubts about Git. Each answer links to the page where the topic is covered in full.
What is the difference between Git and GitHub?
Git is the version control tool that runs on your computer and records the history of your files. GitHub is a website that hosts Git repositories online so people can share and collaborate on them. You can use Git without GitHub, but GitHub always uses Git underneath. See What is Git and the GitHub section.
Do I need an internet connection to use Git?
No. Git is distributed: your clone holds the full
history, so you can commit, branch, inspect the log and go back in time
completely offline. You only need a connection to exchange commits with a remote
(clone, fetch, push, pull).
What is the difference between add and commit?
git add moves changes into the staging area — a draft of your next
commit. git commit records everything staged as a permanent point in
history. Staging first lets you choose exactly what goes into each commit.
See The three areas.
I ran git commit and an editor full of text opened. What happened?
You committed without a message (-m), so Git opened your default editor to
write one. Type a short message on the first line, save and close the editor.
If it is Vim and you are stuck, press Esc, then type :wq and press
Enter to save and quit. To avoid this, always commit with
git commit -m "your message".
How do I write a good commit message?
Keep it short, in the imperative mood, and describe what the commit does:
Add stop-word list, not stuff or fixed things. One coherent change per
commit. Message conventions are covered as a workflow topic in
GitHub § Workflow.
I made a mistake in my last commit. Can I undo it?
Yes, if you have not pushed it yet. Use git reset --soft HEAD~1 to undo
the commit while keeping its changes staged, fix things, and commit again.
If you already pushed and shared it, use git revert instead. See
Undoing changes.
I changed a file and want the original back. How?
If the change is not committed, git restore <file> discards it and restores
the last committed version. Careful: uncommitted changes discarded this way
are gone for good. See Undoing changes.
What is a merge conflict and did I break something?
Nothing is broken. A conflict happens when two branches changed the same
lines of a file and Git cannot decide which version to keep, so it asks
you. Edit the file, remove the <<<<<<<, =======, >>>>>>> markers,
leave the text you want, then git add and commit. The
Example walks
through one step by step.
What is the difference between git pull and git fetch?
git fetch downloads new commits from the remote but does not change
your working files. git pull does a fetch and merges those commits into
your current branch in one step. See Commands § git pull.
Should I commit my virtual environment or __pycache__?
No. Those are generated locally and do not belong in the history. List them
in a .gitignore file so Git ignores them.
This project's .gitignore is a good template.
I accidentally committed a file that should be ignored. Now what?
Add it to .gitignore, then stop tracking it with
git rm --cached <file> and commit. The file stays on your disk but leaves
the repository. See Commands § .gitignore.
What does HEAD mean?
HEAD is a pointer to where you currently are in the history — normally
the latest commit of the branch you are on. Notations like HEAD~1 mean
"one commit before HEAD". See Branches.
Is it safe to delete a branch after merging it?
Yes. Once a branch is merged, its commits live on in the target branch, so
git branch -d <branch> only removes the pointer, not the history. See the
Example.