Clear
- Add a check for an empty task
- Fix login with a wrong password
Git remembers versions of your code, lets you go back to a working state and work together. GitHub is a website where copies of such projects are kept.
A commit is a saved snapshot of the project with a clear description.
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main
git init
git status
git add app.py
git commit -m "Add the home page"
git log --oneline
git add command added it to the next commit.git commit command wrote the snapshot into the history.The .gitignore file lists what Git should not track.
.venv/
__pycache__/
*.db
db.sqlite3
.env
If a password or key has already reached a commit on GitHub, deleting the file is not enough: it stays in the history. Treat the key as exposed and replace it with a new one.
A branch lets you build a new feature separately without breaking the working version.
git switch -c search-form
git add .
git commit -m "Add a search form"
git switch main
git merge search-form
git branch -d search-form
A conflict means two branches changed the same line. Open the file, keep the version you need, remove the markers <<<<<<<, ======= and >>>>>>>, then run git add and git commit.
First create an empty repository on github.com.
git remote add origin https://github.com/USER/REPO.git
git push -u origin main
git pull
git add .
git commit -m "Fix the login form"
git push
Before undoing anything, look at the current state with git status.
| Situation | Command | Important |
|---|---|---|
| Unstage a file | git restore --staged app.py | The edits in the file stay |
| Discard edits in a file | git restore app.py | Unsaved edits are lost for good |
| Undo a commit that is already pushed | git revert abc1234 | Creates a new commit, the history is not broken |
| Fix the message of the last commit | git commit --amend | Only if the commit has not been pushed yet |
The commands git reset --hard and git push --force can delete work for good. A beginner is better off without them.
Describe what changed and why. In a month you will read the history like the project's diary.
Your code is on GitHub. All that is left is to put the site online.