Skip to content

Instantly share code, notes, and snippets.

@adeluccar
Last active June 27, 2025 15:07
Show Gist options
  • Save adeluccar/8674e4aa345c099bdeed685b7d9e1fa7 to your computer and use it in GitHub Desktop.
Save adeluccar/8674e4aa345c099bdeed685b7d9e1fa7 to your computer and use it in GitHub Desktop.
Step-by-step guide for working with feature branches in a GitHub repo: clone, branch, commit, push, open a pull request, merge (preferably squash or rebase), and clean up local and remote branches.

Git Workflow: Feature Branch with GitHub

  1. Clone the repository

    git clone [email protected]:your-brother-username/repo-name.git
    cd repo-name
  2. Create and switch to a feature branch

    git checkout -b your-feature-name
  3. Make code changes...

  4. Stage and commit changes

    git add .
    git commit -m "Describe your feature"
  5. Push the feature branch to origin and set upstream

    git push -u origin your-feature-name
  6. Open GitHub and create a pull request from your-feature-name into main

  7. You can continue making changes, committing, and pushing to the same branch

    git add .
    git commit -m "Follow-up changes"
    git push

    These commits will be automatically added to the open pull request.

  8. Once the feature is complete, merge the pull request using the GitHub interface
    It’s usually better to use squash merge or rebase merge rather than a merge commit, to keep the main branch history clean

  9. Switch back to the main branch locally

    git checkout main
  10. Pull the latest changes from origin

    git pull origin main
  11. Delete the local feature branch

    git branch -d your-feature-name

    If you used a squash merge or rebase merge in GitHub:

    git branch -D your-feature-name
  12. Delete the remote feature branch

    git push origin --delete your-feature-name

    Or delete it directly in the GitHub interface after merging the pull request

@adeluccar
Copy link
Author

This one is for repositories you control (origin) as opposed to forks from another repo (upstream).

@Madeluccar
Copy link

Excellent guide!

Understood everything. Thank you for explaining it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment