Problems, Safety, and GitHub Hygiene
Last updated on 2026-03-06 | Edit this page
Overview
Questions
- What common problems will I encounter when using git?
- How do I undo mistakes safely?
- How should I organise my repository and collaborate with others?
Objectives
- Handle common git pitfalls (empty directories, wrong commits)
- Undo changes using revert, discard, and reset (beginner-safe)
- Explain the difference between public and private repositories
- Describe protected branches, collaborators, and permissions
- Use GitHub issues effectively
Common Problems
Empty Directories
Git tracks files, not directories. If you create an empty folder, git will ignore it.
Workarounds:
- Add a placeholder file called
.gitkeepinside the directory. - Make sure every directory contains at least one meaningful file.
Accidentally Committed the Wrong File
If you committed a file by mistake (for example a large data file or credentials):
- Don’t panic. The commit is only local until you push.
- In GitHub Desktop, right-click the commit in History and choose Revert this Commit.
- Add the file pattern to
.gitignoreso it is not tracked in the future.
Credentials and secrets
Never commit passwords, API keys, or other secrets. If you accidentally push a secret to GitHub, consider it compromised — rotate the credential immediately and remove it from the repository history.
Undoing Changes
There are several ways to undo work in git. Here is a beginner-friendly overview:
| Situation | Action in GitHub Desktop | What happens |
|---|---|---|
| Changed a file but have not committed | Right-click the file → Discard changes | File returns to the last committed state |
| Committed but have not pushed | Right-click the commit → Revert this Commit | A new commit is created that undoes the changes |
| Already pushed | Use Revert this Commit and push again | A new revert commit is added to the remote |
A note on rebase
You may encounter the term rebase in online tutorials. Rebasing rewrites commit history and is an advanced technique. Do not use rebase on shared branches unless you fully understand the implications — it can cause serious problems for collaborators. Stick with merge for now.
Repository Visibility
| Setting | Who can see the repo | Who can contribute |
|---|---|---|
| Public | Anyone on the internet | Only collaborators (unless forked) |
| Private | Only you and invited collaborators | Only collaborators |
Choose private for sensitive or unfinished work. Choose public when you want to share your project with the world.
Protected Branches
Teams often protect the main branch so
that:
- No one can push directly to
main. - All changes must go through a pull request.
- Pull requests require at least one approving review before merging.
This prevents accidental breakage on the stable branch.
- Go to your repository on GitHub.
- Click Settings → Branches.
- Under “Branch protection rules”, click Add rule.
- Enter
mainas the branch name pattern. - Check Require a pull request before merging and other options as needed.
Collaborators and Permissions
To give someone access to your private repository (or push access to a public one):
- Go to Settings → Collaborators.
- Click Add people and search for their GitHub username.
- Choose a permission level (Read, Write, or Admin).
GitHub Issues
Issues are used to track tasks, report bugs, and discuss ideas. Good practices:
- Clear title: summarise the problem or request in a few words.
- Description: explain the context, steps to reproduce (for bugs), and expected behaviour.
-
Labels: use labels like
bug,enhancement,questionto categorise. -
Linking: reference issues in commit messages or PRs
using
#123syntax.
Documentation and README files
Exercise: Your Troubleshooting Checklist
Create a short checklist titled “What to do when something went wrong”. Include at least five items covering the scenarios discussed above.
- Unwanted changes to a file? → Discard changes in GitHub Desktop.
- Wrong commit (not yet pushed)? → Revert the commit in GitHub Desktop.
- Wrong commit (already pushed)? → Revert and push the revert commit.
- Committed a secret? → Rotate the credential immediately. Remove from history if possible.
-
Empty directory not showing up? → Add a
.gitkeepfile. - Merge conflict? → Open the file, resolve the markers, commit, and push.
- Cannot push to main? → The branch is probably protected. Create a branch and open a pull request instead.
- Git does not track empty directories — use
.gitkeepas a placeholder. - Use Discard changes for uncommitted edits and Revert for commits.
- Never commit secrets; rotate any that are accidentally pushed.
- Protected branches enforce a pull request workflow.
- Issues help organise work; use clear titles, descriptions, and labels.