/learning-git

Learn Git and GitHub by contributing to this repo

MIT LicenseMIT

learning-git

Learn Git and GitHub by contributing to this repo!

In the FAQs below we've got a bunch of questions without answers. Do some Googling to find these answers, and create a pull request to have your answer listed here. See the CONTRIBUTING document for more information on how to contribute to this repo.

If you have any other questions not listed here, please raise a PR to have it added. There's no need to answer it unless you want to.

Git FAQ

  • Q: I made a typo in my commit message, how can I amend it?

  • A: git commit --amend allows you to change the last commit message. You can add a -m "commit message" to add a message at the same time.

  • Q: Can I see a log of the commits that have been made on this repository?

  • A: git log

  • Q: What are some Graphical User Interfaces(GUI, pronounced "gooey") that I can use with Git?

  • A: GitKraken, SourceTree, Git

  • Q: I have accidentally staged something I don't want to commit. Can I reset only that file?

  • A: Yes. To unstage a file type git reset HEAD <filename>. You can leave HEAD out as it is implicit.

  • Q: I would like to see what the repo looked like at a given version. How can i checkout that version?

  • Q: How can I see a diff of what's changed in the files I've changed but not committed? How about just the files I've staged?

  • A: git diff shows the unstaged changes. git diff --cached shows the staged changes.

  • Q: Can Git show me what's changed in the previous commit?

  • A: Type in git show.

  • Q: How can I add only parts of a file I've changed?

  • Q: How can I revert a commit?

  • A: Use git revert HEAD. When you revert a commit, you are actually making a new commit which just reverses the changes. You should use this if you've already pushed your changes to a remote - otherwise, see git reset.

  • Q: I keep accidentally adding files I don't want to commit (e.g. compiled code, files with passwords etc.), how can I ignore these files?

  • Q: What's the difference between git pull and git fetch?

  • A: git pull = git fetch + merge. git pull gathers commits from the target branch and automatically merges them with your current branch. git fetch gathers commits from the target branch and stores them in your local repository. It does not merge these commits with the commits in your current branch. To integrate the commits into your current branch use merge. git fetch is useful if you want to review any updates to the target branch before merging them with your own. It makes it easier to spot and fix any conflicts that may occur during the merge.

  • Q: How can I clean the repo of any untracked files, i.e. removing new, unstaged files without manually rming all of them?

A bit more challenging questions:

  • Q: Windows behaves differently to most operating systems, in particular in how it handles line endings (Windows uses CRLF whereas all other operating systems use just LF). How can I make sure that all commits use the same line endings? What are the consequences of not caring about this?

  • Q: I need to change branch, but Git won't let me because I have modified some files. I don't want to commit these yet, can I stash them away for later?

  • Q: How can I make it so that git diff also displays the diff of new file's I've introduced?

  • Q: What's the difference between a merge and a rebase?

GitHub FAQ

  • Q: How can I see who wrote a specific line in a file, so that I can blame the right person?

  • A: 'Git blame ' can ensure the correct person is punished accordingly.

  • Q: How can I add collaborators to this project?

  • Q: How can I create my own organisation?

  • Q: How can I create a project issue tracker?

  • Q: How can I create a website for my repository? (Author's note: This violates some sort of universal law: it's free, easy and fast!)

A bit more challenging questions:

  • Q: How can I make it so that GitHub remembers my computer, and doesn't ask for username and password all the time?

  • Q: What's the difference between cloning over HTTPS and SSH?

  • Q: Would you recommend a different method (simpler perhaps?) for repo maintainers to contribute?

  • Q: What are some common branching strategies? What strategy does our CONTRIBUTING.md file recommend?