A · DailyBeginner40 min read
3. Branches, remotes & push
Git & GitHub · 48 pages source format
Branches are cheap pointers. main stays stable. Feature branches isolate work. Remote tracks GitHub.
What you'll learn
- branch / checkout / switch
- push -u origin
- pull / fetch
- Tracking branches
Create and switch branches
git switch -c feature/login. Work. commit. main unchanged until merge.
git switch -c feature/hello
echo "hello" > hello.txt
git add hello.txt
git commit -m "feat: add hello"
git switch main
# hello.txt not here
git switch feature/hello
# hello.txt backDo this now
Create feature branch, add file, commit, switch back to main — file gone (expected).
Clear?
Push and set upstream
git push -u origin feature/hello first time. Later git push suffices.
Do this now
Push feature branch to GitHub. Verify on github.com.
Clear?
Fetch and pull
git fetch downloads remote changes without merging. git pull = fetch + merge (or rebase with --rebase).
Do this now
Edit on GitHub web UI. fetch. pull. See local update.
Clear?