Skip to content

Instantly share code, notes, and snippets.

@AlexanderHott
Created November 5, 2025 13:18
Show Gist options
  • Select an option

  • Save AlexanderHott/18e6e85b0c579ca291bec19b2ffe7e94 to your computer and use it in GitHub Desktop.

Select an option

Save AlexanderHott/18e6e85b0c579ca291bec19b2ffe7e94 to your computer and use it in GitHub Desktop.
Git workflow

This is the git workflow I use that allows multiple people to collaborate on the same Git(Hub) repository.

You should start this when you do not have any local changes (your code on your computer and GitHub is the same).

1) Create and switch to new branch.

I like to prefix my branches with an indicaton of what it is, for example feat/ for features, fix/ for bug fixes, doc/ for documentation changes. I also only use lowercase with - for the branch name.

git switch -c feat/metered-payments

2) Make some changes and push

Keep your changes brief. I aim to stay under 200 lines of code per PR. Once you have some local changes, stage them with git add -A or git add -p followed with a git add -A. I don't use git add . because if you aren't in the root directory of your project, you might miss some files.

Commit your changes git commit -m "implement metered payments". Repeat as many times as you need.

Once you made all your changes, push them with git push.

Git may tell you that the remote branch doesn't exist. It will give you a command to push and create the remote branch, but I have the following set in my git config (~/.config/git/config) so it does that automatically.

[push]
	autoSetupRemote = true

3) Make a PR and review it

Once your new code is pushed on a separate branch on GitHub, make a Pull Request (PR) from your branch (feat/metered-payments) to your main branch (main). This is a good place for teammates/co-workers/you to review your code.

Once it's reviewed, select "Squash and Merge", which squashes all the commits from your PR into a single one, making navigating past commits easier.

You can delete the remote branch if you want.

4) Sync your local machine

Now we want to sync our local git repo.

git switch main
git pull

and we can remove the old branch.

git fetch --all --prune

Now you are back to before 1), so you can repeat the process.

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