Skip to content

Instantly share code, notes, and snippets.

@gsambrotta
Last active May 22, 2021 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsambrotta/4011f679e8f83b23ad1a90129f95c95b to your computer and use it in GitHub Desktop.
Save gsambrotta/4011f679e8f83b23ad1a90129f95c95b to your computer and use it in GitHub Desktop.

Creating repo

A person in your team create the repo and host on his/her github account.

    $ cd my-projects-folder/ 
    $ mkdir new-project && new-project
    $ git init
    $ git add README.md
    $ git commit -m "first commit"
    $ git branch -M main
    $ git remote add origin git@github.com:your-github-repo-url
    $ git push -u origin main

Then go to settings > manage access and add your teammate as collaborator of your repo.

So far you will have just one branch, main, which it will be your production branch. Where all you WORKING code will be. No code will have to be pushed directly to main. The code that is in main, come from Pull Requests that are merged in.

Working on a new feature

First, we need to be sure our local branch is up to date with Github code. So we need to fetch changes from main and re-apply ours on top.

Go to your project directory:

git checkout main
git fetch origin main
git rebase main 

If git rebase main doesn't work, you can do git pull main

If you get any conflict with your code, please fix the conflict before moving forward.

  • Do this EVERY TIME you start to work on a new feature.
  • Do this EVERY TIME a new PR is merged in main
  • Do this as often as possible and you shoudl have as little code conflict as possible.

Now we can create our branch and work on our feature:

git checkout -b my-fancy-new-fetaure
git status // check that you are pushing exactly the files you want to merge!
git add . // or git add filename
git commit -m "I just created this amazing feature!"
git push origin my-fancy-feature

After pushing your code to to Github, go to Github and create a new Pull Request. Your PR must be:

  • base: main - compare: my-fancy-new-feature
  • write a description of your work for your team mate
  • scroll down and check your code changes. Are the one that you really want to merge to main?
  • add your teammates as reviewers
  • create PR

Next steps wil be for your team mate to do a code review. When someone will have approved your code, you or one of your team mate can merge the PR. After the PR is merge, go to your code and checkout main and check taht the application work properly.

git checkout main
git fetch origin main
git rebase main
npm run dev

... or check on Vercel, if you already deployed the app there.

Review Pull Request

When one of your teammates ask you to review their PR you can follow those steps:

  • Go to Github > Pull Request > click on the PR you want to review
  • Read title and description to get an idea of what is about
  • Go to "Files Changed" and review the code
  • If you want to leave comments on the code, hover the line where you want to leave your comment, you will see a small blue + icon show up. Click on it and write the comemnt.
  • When you are done with the review, go to the green button on the top right "Review changes". and add your review. If you like the code and thinkis good to merge to main, select "Approve" and "Submit Review". If you think there are stuff to changes, click on "Request Changes" and then "Submit review".
  • If you request for changes, wait your teammate to fix the code.
  • If you approved, you can merge the PR.

REMEMBER TO UPDATE YOUR LOCAL MAIN BRANCH AFTER YOU MERGED A PR!

What to do if they ask me to fix/change my code?

If you got a comments of changing something from the code review, go to your terminal, go to main, be sure your main branch is up-to-date with Github code and then update your feature branch:

 $ git checkout main 
 $ git fetch origin main
 $ git pull origin main
 $ git checkout your-feature-branch
 $ git rebase main // this is to get the last changes from Github to your on-working branch

If you have conflict, you need to fix them. If not, you can work on your branch, make the changes your teammates asked you to do and then push again to your feature branch and ask again for review/merge if was a small changes that don't need review.

I'm working on a task and someone just merged a PR

You are working on a feature and one of your teammate just merge a PR to main where there is code you think it will have conflict with yours. Then please follow the steps on: "What to do if they ask me to fix/change my code?"

Cannot merge PR because of Conflict

If on your PR you get a message that you need to update your code before is possible to merge, please follow the steps on "What to do if they ask me to fix/change my code?"

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