Skip to content

Instantly share code, notes, and snippets.

@dashaday
Last active February 22, 2020 20:30
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 dashaday/4086c8322fe64c3e53a2810b1dbecd46 to your computer and use it in GitHub Desktop.
Save dashaday/4086c8322fe64c3e53a2810b1dbecd46 to your computer and use it in GitHub Desktop.

Working in Groups with Git

Disclaimer: I'm not an expert at git, this is simply a written guide from Prof Stolley's lectures on 03-04-2019 and 02-19-2020. I just thought it would be a helpful thing to have.

After creating an organization and a repository on GitHub, these are the things you have to do.

Forking πŸ‘

This allows you to create a personal copy of the team repository to work with. By having a forked copy of the repo, you'll be able to develop and play and mess around with the code without changing the team's copy!

  1. Fork
    • Click Fork from your organization's group repository
    • You'll then be redirected to your own forked repository
  2. Clone
    • Click 'Clone or Download' from your personal forked repository
    • Copy link
    • In your command line, navigate to the directory where you'd like to your repository to be in
    • git clone [your-clone-link]
  3. Add Remote link
    • Go to your group's repository on GitHub
    • Copy clone link (similar to step 2 above)
    • In your command line, navigate into your cloned directory
    • git remote add [remote-name] [group-repo-clone-link]
      • 'remote-name' is the name you'd like to use to reference your team's repository
      • Ex. git remote add group git@github.com:team/this-project
    • To check your setup: git remote -v
      • There should be values for 'origin' and your remote name

Branching 🌳

From the master branch, you should create feature/development branches. The master branch is supposed to be your best working version so far. This is the same version as your team repository's master branch. From your master, create branches for every feature you're working on. Name it descriptively as well (ex: order-form-submit-btn).

Creating Branches

  1. Make branch (per feature)
    • From master branch: git checkout -b [branch-name]
    • This command allows you to create and go into your new branch
  2. Do your development work here. Git add and commit as usual
  3. Push to your remote repository, specifying the branch name.
    • git push origin [branch-name]

Deleting Branches

Delete branches after they've been merged to master or after tagging.

Locally

  1. Checkout to master branch: git checkout master
  2. Delete branch: git branch -d [branch-to-be-deleted-name]
    • If error appears because this branch hasn't been merged, use force delete: git branch -D [branch-to-be-deleted-name]

Remotely

To delete your branch remotely:

  1. Go to your master branch
  2. Delete: git push origin :[branch-to-be-deleted-name]

You can also do this on the GitHub interface.


Making a Pull Request πŸ™

A Pull Request is basically you asking the team if your work is worthy enough to be part of the project. By creating a PR, others will be able to see your proposed additions or changes and decide if it'll be merged.

  1. Go to GitHub -> your forked repository
  2. Click Pull Request
    • You should see a notification there with a clickable 'Pull Request' link
    • You'll be redirected to the team repo
  3. Fill up fields
  4. Click 'Create Pull Request'

Merging in Team Repository πŸ‘Œ

As a part of this team, you're not only making changes, you're reviewing them too. So don't forget to check on your team repository's pull requests!

To check others' pull requests:

  1. Go to group repo -> 'Pull Requests'
  2. Click on the earliest commit
  3. Comment notes or edit if necessary
    • 'LGTM' is a common comment meaning 'looks good to me'
    • Alternately, you could also point out some issues or fixes
  4. Last person to check it should merge pull request if there's a unanimous LGTM

Updating Local Files ✨

The team's master branch has been updated! You should probably update yours too. This makes sure that any work you do fits with the team's development so far. It will also make merges easier for everyone when you do a PR. Do this often.

git pull [remote-name] master

Ex. git pull group master


Conflicting Pull Request: Rebasing πŸ”¨

This happens when there are new updates on the master branch that doesn't exist or clashes with your PR (for example: a new PR might have been merged just before yours). You will need to resolve this by rebasing.

When you create a pull request and a message appears that your branch can't automatically merge:

  1. Add a comment about the error then continue and click 'Create Pull Request'

  2. Resolve your conflicts locally (don't click the 'Resolve' button on GitHub)

    a. Update master branch

    • Go to master branch: git checkout master
    • Update your master branch from team repo: git pull group master
    • Push updated master branch to your remote repo: git push origin master

    b. Rebase

    • Move into your feature branch: git checkout [branch-name]
    • Rebase: git rebase master
    • This will rebase your branch with the master (which is updated from the team repo)
    • If successful, check your PR on GitHub. It should let you know that your PR will be able to merge.

If the rebase fails:

  1. Manually edit
    • Open file in Atom and manually edit what should be kept
  2. Complete rebase
    • git add [filename]
    • git rebase --continue
  3. Push to branch
    • git push origin [branch-name]
    • !ERROR will occur but it's okay
    • git push origin [branch-name] -f
  4. Check
    • Check your PR on GitHub. It should let you know that your PR will be able to merge.

Tagging and Releasing πŸ”–

This will allow GitHub toβ€”sort ofβ€”put a pin at a point in your development. Tagging will let GitHub help you in creating a Release as well.

Basics

To tag: git tag [tag-name] For example: git tag 1.0.0

Update Previous Tagged Version

  1. Checkout to new branch with tagged version
    • git checkout -b [new-branch-name] [tag-name]
    • This will create a new branch and move you into it. This branch will have the state of your project from the version when you tagged it.
    • Ex. git checkout -b 1.0.1 1.0.0
  2. Tag this
    • git tag [tag-name]
    • Ex. git tag 1.0.1
  3. Push to Git
  4. Delete your branches locally and remotely. View instructions here.

Release It!

  1. After you've tagged the version of your project you want to release, go to your GitHub repository
  2. Click on 'Releases' tab
    • You should be able to view your tags here
  3. On the tag you'd like to release, click the three-dotted icon on the right -> 'Create Release'
  4. Fill out fields and the release summary, referring to specific commits
  5. Select 'Create Release' or 'Save Draft'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment