Git basics for GitHub: essential commands
You have a GitHub repository – now what? Learn the core Git commands to clone, commit, push, pull and keep your code in sync. No prior Git experience needed.
clone
edit
commit
push
GitHub
Copy a repository from GitHub to your local machine. You only need to do this once per project.
git clone https://github.com/username/repo.gitCloning into 'my-first-project'...
remote: Enumerating objects: 3, done.
✔ done.
This creates a folder named my-first-project with all files and the full Git history.
cd my-first-project to enter the folder. Then you can start working.Shows which files are modified, staged, or untracked. Use it often – it's your Git dashboard.
git statusOn branch main
Changes not staged for commit:
modified: index.html
Untracked files:
style.css
🔴 Red = modified but not staged · 🟢 Green = staged (ready to commit)
Tell Git which changes you want to include in the next commit.
git add filename or git add . (all files)$ git status
Changes to be committed:
new file: style.css
modified: index.html
git add -p lets you stage parts of a file (advanced but handy).Create a permanent checkpoint with a descriptive message.
git commit -m "your message"[main 1a2b3c4] add style.css and update homepage
2 files changed, 42 insertions(+), 3 deletions(-)
✅ The commit is now saved locally. The message should be clear (e.g., "fix login bug", not "update").
Send your local commits to the remote repository (GitHub).
git push origin mainEnumerating objects: 5, done.
To https://github.com/yourname/my-first-project.git
a1b2c3d..e4f5g6h main -> main
Now visit your GitHub repo – your changes are live!
If teammates (or you from another computer) pushed changes, pull brings them to your local machine.
git pull origin mainremote: Counting objects: 4, done.
a1b2c3d..e4f5g6h main -> origin/main
Updating a1b2c3d..e4f5g6h
Fast-forward
README.md | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Always pull before you start working to avoid merge conflicts.
Shows a list of all commits with author, date, and message.
git log --oneline (compact view)e4f5g6h (HEAD -> main, origin/main) add style.css and update homepage
a1b2c3d initial commit with README
Typical workflow (all together)
# after cloning or pulling
git pull origin main # get latest
# make changes to files (edit, add, delete)
git status # see what's changed
git add . # stage all changes
git commit -m "add new feature"
git push origin main # send to GitHub
That's the daily cycle: pull → edit → add → commit → push.
Frequently Asked Questions (Git basics)
git fetch downloads new data from GitHub but does not integrate it into your working files. git pull = fetch + merge (it updates your files). For beginners, git pull is simpler.
git add .) then run git commit --amend. This updates the previous commit instead of creating a new one. Only amend if you haven't pushed yet!
origin is a default alias (shortcut) for your remote repository URL. You can see it with git remote -v. You could rename it, but most people keep "origin".
git reset unstages files. Example: git reset HEAD index.html removes that file from staging. If you want to unstage everything: git reset.
main as default branch name (since 2020). Older repositories may use master. Both work the same; just use the one your repo shows. Command: git push origin main or git push origin master.
<<<<<<<. Don't panic – open the file, decide which part to keep, remove the markers, then git add and commit. It's a normal part of collaboration.
git pull ensures you have any remote changes, avoiding rejected pushes. Many teams do pull → work → commit → pull again → push.
.gitignore in your repo and list patterns (e.g., node_modules/, .env). Already tracked files won't be ignored – you'd need to git rm --cached them. Most templates are available when creating a repo.
git checkout -- filename restores it. If you already committed the deletion, you can revert that commit. Git keeps history forever (almost).
git pushed repositories and adds collaboration features (Issues, PRs, Actions). You can use Git without GitHub, but GitHub relies on Git.
You've just learned the daily Git workflow – practice by cloning a repo and making a commit!