Git Foundations / Work With a Remote

A feature-branch workflow

Lesson 28 of 33. Open to read. No account needed.

One Feature, One Branch

Most teams keep main working and deliver each change on its own short-lived branch. The branch lets a change be shared, reviewed and finished without holding anyone else up, and it disappears once its work is on main. This lesson puts the module's commands together into that routine.

Six steps repeated for each feature: branch from an up-to-date main; commit small, focused changes and say why; share with git push -u origin and the branch name; keep current by merging main into the branch; integrate by merging into main and pushing; clean up by deleting the branch locally and on origin. Teammates then run git fetch --prune.

The Routine

  1. Branch from an up-to-date main. git switch main, git pull, then git switch -c <branch> with a name that says what the change is.

  2. Commit small, focused changes, each with a message that says what and why. git commit -m "<summary>" -m "<why>" adds the reason as a body.

  3. Share the branch with git push -u origin <branch>, so others can see it and it is backed up.

  4. Keep it current. If main moves on, pull main, then merge it into your branch so you test against the latest work. Because the branch is shared, merging is safer than rebasing.

  5. Integrate. Switch to main, pull, merge the branch and push. On many teams this step happens through a review on a hosting service, which the optional module covers.

  6. Clean up. Delete the branch locally with git branch -d and on the remote with:

    git push origin --delete <branch>
    

    Teammates' clones still remember the old remote branch. git fetch --prune removes remote-tracking branches whose branch is gone from the remote.

Making Changes Easy to Review

Before you ask someone to look at a branch, make it easy to understand:

  • Small scope: one feature or fix per branch. A branch that also renames files and reformats code is hard to check.
  • Clear history: focused commits with meaningful messages; tidy "wip" commits before sharing, as in the rebase module.
  • A description of why: what problem the change solves and anything a reviewer should check. The commit body is a good place to start.

Exercise: Deliver Two Features Through the Shared Remote

Asha adds a FAQ page and Ravi a contact page, each on a branch, and both reach main through shared.git.

Starting state: Git configured as in the configuration lesson. You will rebuild the team practice set, and remove it at the end of this lesson.

  1. Rebuild the practice set:

    cd ~/git-practice
    rm -rf team
    mkdir team
    cd team
    git init --bare -b main shared.git
    git clone shared.git asha
    cd asha
    git config user.name "Asha Rao"
    git config user.email "asha@example.com"
    cat > README.md <<'EOF'
    # Team notes
    
    We meet on Mondays.
    Bring your laptop.
    EOF
    git add README.md
    git commit -m "Add team notes"
    git push -u origin main
    cd ..
    git clone shared.git ravi
    cd ravi
    git config user.name "Ravi Kumar"
    git config user.email "ravi@example.com"
    cd ..
    
  2. As Asha, start the FAQ on a branch and share it:

    cd asha
    git switch main
    git pull
    git switch -c add-faq
    cat > faq.md <<'EOF'
    # Questions new members ask
    
    Where do we meet? Room 4.
    What should I bring? Your laptop.
    EOF
    git add faq.md
    git commit -m "Add a FAQ page" -m "New members ask the same questions every week."
    git push -u origin add-faq
    
  3. As Ravi, start the contact page the same way:

    cd ../ravi
    git switch main
    git pull
    git switch -c add-contact
    cat > contact.md <<'EOF'
    # Contact
    
    Message Ravi with questions about the meetings.
    EOF
    git add contact.md
    git commit -m "Add a contact page" -m "People keep asking who organises the meetings."
    git push -u origin add-contact
    
  4. As Asha, integrate the FAQ and clean up:

    cd ../asha
    git switch main
    git pull
    git merge add-faq
    git push
    git branch -d add-faq
    git push origin --delete add-faq
    

    The merge fast-forwards, because main had not moved. The last command reports - [deleted] add-faq.

  5. As Ravi, bring the new main into the contact branch:

    cd ../ravi
    git switch main
    git pull
    git switch add-contact
    git merge --no-edit main
    git push
    

    The branch now contains the FAQ as well, so Ravi can check that his page works with it.

  6. As Ravi, integrate the contact page and clean up:

    git switch main
    git merge add-contact
    git push
    git branch -d add-contact
    git push origin --delete add-contact
    git log --oneline --graph
    
  7. As Asha, catch up and remove stale names:

    cd ../asha
    git fetch --prune
    git pull
    git branch -a
    git log --oneline
    

    git fetch --prune reports - [deleted] for origin/add-contact. git branch -a lists only main and origin/main, and possibly origin/HEAD, a pointer to the remote's default branch. The log contains both features.

Success: both features are on main in shared.git, and the finished branches are gone from both clones and from the remote.

If something differs:

What you seeLikely causeNext step
git branch -d says is not fully mergedThe branch was not merged into the branch you are onSwitch to main, merge, then delete
remote ref does not existThe remote branch was already deletedNothing to do; run git fetch --prune
Old branches still listed under remotes/originThe clone has not prunedgit fetch --prune
The push in step 4 or 6 is rejectedThe other collaborator pushed firstgit pull, then push again

Independent task: as Ravi, deliver one more small feature from start to finish: a directions.md page saying how to find Room 4. Use a branch and a commit message with a body that explains why, share the branch, integrate it into main and clean it up everywhere. Then show from Asha's clone that main has the page and no feature branch is left anywhere.

  1. Remove the whole practice set. This module is finished:

    cd ~/git-practice
    ls
    rm -rf team
    ls
    

Check Your Understanding

A teammate opens a branch for review called updates with 23 commits. It adds a new booking form, renames half the files in the project and fixes a typo on the home page. Most commit messages say "wip" or "more changes", and there is no description. List what makes it hard to review, and how you would improve it.

Answer and Reasoning

Independent task

In ravi:

git switch -c add-directions
cat > directions.md <<'EOF'
# Directions

Room 4 is on the first floor, next to the library.
EOF
git add directions.md
git commit -m "Add directions to Room 4" -m "Two new members got lost last week."
git push -u origin add-directions
git switch main
git pull
git merge add-directions
git push
git branch -d add-directions
git push origin --delete add-directions

Then in asha:

git fetch --prune
git pull
git branch -a
git log --oneline -1

Asha's newest commit is "Add directions to Room 4", and git branch -a lists no feature branches, locally or under remotes/origin.

Understanding check

  • Too much scope: three unrelated changes in one branch. Split them into separate branches: the booking form, the renames and the typo fix.
  • Vague name: updates says nothing; add-booking-form would.
  • Unclear history: 23 commits labelled "wip" make it impossible to follow the reasoning. Tidy them into a few focused commits before sharing.
  • No description: a reviewer cannot tell what problem the change solves or what to check. Explain why in the commit bodies and in the request for review.

References

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy