class: center, inverse, middle, title-slide

Let's Write a Paper!

Part III - Collaboration & Workflow Styles

Patrick Anker

.ties-footer[

Global TIES for Children

]


class: middle, center

Before we begin...

If you'd like to download any of the materials for this presentation, check out

>> the workshop's website <<

r "\U1F680"


Agenda

.pull-left[

So far, we have covered

]

.pull-right[

Today, I want to cover:

  1. How to merge work from other branches
  2. Issue tracking
  3. Different collaboration styles & commit conventions

]


class: middle, center, inverse

Merging

.yellow[]


Merging

Collaboration is only useful if we are able to combine our work on our different branches. We achieve this using a git merge

.definition[

Merge

A mechanism that takes two (or more) histories and reconciles the differences in a line-wise fashion.

]

We've already used a mechanism that implements a merge before, and that's the Pull Request feature on Github! However, Pull Requests are really some nice window dressing around merges, and sometimes it's useful to merge work outside of the context of a Pull Request.


Merging

Consider this example:

.pull-left[

I'm working on a particular section of a report, and things are going swimmingly. However, I noticed that something in your analysis would be very nice to include in my report, but your analysis work was already merged into main via a Pull Request.

How can I get your analysis work into my branch so I can make the changes in my report prior to creating a PR?

]

.pull-right[

How to get analysis work into my branch?

]


Merging

.center[with a git merge!]

.center[.red[with a merge commit!]]


Merging

.center[Github also makes a merge commit]

.center[Github also makes a merge commit once a Pull Request is merged.]


Merging

To perform this kind of merge, all you need to do is follow these steps:

.pull-left.font12[

Action | Example :------|:-------- 1. Switch to the branch you'd like to merge in | git checkout main

]

.pull-right[

How to merge sync 1: git checkout <source>

]


Merging

To perform this kind of merge, all you need to do is follow these steps:

.pull-left.font12[

Action | Example :------|:-------- 1. Switch to the branch you'd like to merge in | git checkout main 2. Download changes to your computer | git pull

]

.pull-right[

How to merge sync 2: git pull

]


Merging

To perform this kind of merge, all you need to do is follow these steps:

.pull-left.font12[

Action | Example :------|:-------- 1. Switch to the branch you'd like to merge in | git checkout main 2. Download changes to your computer | git pull 3. Switch back to your branch | git checkout -

]

.pull-right[

How to merge sync 3: git checkout -

]

.footnote.font12[

The - is a shortcut for "previous branch". It's just like cd - from moving around th Terminal!

]


Merging

To perform this kind of merge, all you need to do is follow these steps:

.pull-left.font12[

Action | Example :------|:-------- 1. Switch to the branch you'd like to merge in | git checkout main 2. Download changes to your computer | git pull 3. Switch back to your branch | git checkout - 4. Merge in the changes! | git merge main

]

.pull-right[

How to merge sync 4: git merge main

]


Merging

These steps are the same for command line and for SourceTree:

  1. Switch to the branch you'd like to merge in
  2. Download changes to your computer, if they don't already exist
  3. Switch back to your branch
  4. Merge in the changes

.pull-left[

Command Line

.font12[

  1. git checkout <target branch>
  2. git pull
  3. git checkout -
  4. git merge <target branch>

]

.font10[

Note: After running git merge you may be thrown into an editor called "vim". Just remember this keystroke sequence and all will be well: :wq<Enter>

]

]

.pull-right.font12[

SourceTree

  1. Double-click on the target branch you'd like to merge in
  2. Click "Pull"
  3. Double-click on the branch you're working on
  4. Click "Merge" and then select the commit that has the target branch's name tagged to it

]

???


class: middle

The Golden Rule of Merging

.red[Merge] to bring someone else's work into your branch; .red[Pull Request] to send your work into someone else's branch

Adhering to this rule will handle much of complexity and confusion that git can cause. This also creates a great social contract for you and your collaborators: adapt from others to create something new for yourself, ask permission to give back to others.


A Tip

Getting A Single File From Another Branch

Suppose that your collaborator has a file change that you want to adopt, but you don't necessarily want to merge in their entire branch. How do you get it?

.pull-left.font12[

As far as I know, this is something you can only do with the command line interface.

You must use the command:

.font10[

git checkout <branch name> -- path/to/file.txt

]

An important thing to know is that this operation .red[overwrites] your work on that file, avoiding a merge conflict. If you want to merge your work, it would be better to use a merge.

]

.pull-right.font10[

git checkout topic -- config/mapping.csv

]

???


class: middle, center, inverse

Merge Conflicts

.yellow[] r "\U1F645" r "\U1F62B"


Merge Conflicts

Even with the best workflow, you will encounter merge conflicts. And that is okay! Embrace the merge conflicts. Accept them.

.center[

.red[]

]

In all seriousness, it is expected that you will encounter merge conflicts if you and your collaborator happen to edit the same line.

.pull-left[

Unlike Box, however, git will tell you where the conflicts arise and guide you on how to resolve them. When you merge something that generates a conflict, you will see this:

]

.pull-right[

>>>>>>> your-current-branch
text that was in your branch
...
=======
text that was in the other branch
...
<<<<<<< branch-youre-merging-in

]


Merge Conflicts

.pull-left[

The merge conflict chunks come in three parts:

  1. >>>>>>> [where you are, often "HEAD"] followed by the content in your branch
  2. ======= - a partition between the two content areas
  3. The content from the branch/commit you're merging in followed by <<<<<<< [what you're merging in]

]

.pull-right[

*>>>>>>> your-current-branch
text that was in your branch
...
*=======
text that was in the other branch
...
*<<<<<<< branch-youre-merging-in

]


Merge Conflicts

.pull-left[

All you need to do is:

  1. Pick the content you want to keep between the two (could be a combination of both!)
  2. Delete the lines with <<<<<<<, >>>>>>>, and =======.
  3. Commit the changes!

]

.pull-right[

>>>>>>> your-current-branch
*text that was in your branch
*...
=======
*text that was in the other branch
*...
<<<<<<< branch-youre-merging-in

]


class: middle, center, inverse

Issues

r "\U1F5D2"


Issues

.pull-left[

Issues are a part of Github's project management suite, like tasks on Asana. Each issue has its own number1 that can be referenced with a pound sign (e.g. #5).

]

.pull-right[

Screenshot of issue list on Github

]

.footnote[

[1]: You can refer to Pull Requests using this scheme, too! Pull Requests are just fancy issues.

]


Issues

.pull-left[

If you want to mark a commit as referncing another issue, just put the commit number in the commit message, e.g. fix bug that would duplicate analysis (#20)

]

.pull-right[

Screenshot of Github with issue numbers automatically hyperlinked in a commit message

]


Why use issues when we have Asana?

This is a practical question that I've tinkered with while working at TIES, and my conclusion for when to use Asana vs. Github issues is as follows:

  1. Use Asana for larger project milestones and roadmaps
  2. Use Github issues to track bugs / unexpected behavior

While there are tools to integrate Asana and Github issues, they aren't perfect for both situations. Keeping this division has so far been fairly successful on the Data Team.


class: middle, center, inverse

Collaboration Styles

r "\U1F469\U200D\U1F4BB" r "\U1F468\U200D\U1F4BB"


Collaborating

There are three main collaboration styles with git:

.pull-left.font12[

  1. Shared repository / central backup
  2. The most common use style
  3. Useful for private projects and projects with a few collaborators
  4. Project leaders need to manage access permissions
  5. Forking
  6. Popular in open source software
  7. Not great for private repositories / projects
  8. Peer-to-peer
  9. Primarily used by UNIX wizards and folks who don't trust central code repos
  10. Hard to know which repo is the "live" repo

]

.pull-right[

Central backup diagram

Forking diagram

Peer-to-peer diagram ]


Collaborating

.pull-left[

In most cases, we should be using the "Shared Repository" model for our projects since we mostly want privacy and security.

By default, all private Github repos are hidden on the NYU Global TIES Github org. You will need to add people to have access (I can help with that).

]

.pull-right[

Central backup diagram

]


Commit Messages

What makes a good commit message? Commit messages are the core description of changes in our git log. You should be able to understand what happened in your repo just by glancing at the log. Remember: this log isn't just for others; this is also for you a couple months or years down the line. These are some suggestions from the wild:

.pull-left.font12[

  1. Use imperative case e.g. "remove routine that was crashing OSF lookup"
  2. Be informative and clear with your messages: don't do "update script.do", do "fixed linear regression syntax"

Totally optional, but I highly recommend the Conventional Commits format as some other tools are out there that can help generate changelogs and other documentation automatically from your commit messages.

]

.pull-right[

Example of decent commit messages

]


class: middle, center, inverse

Questions?



nyuglobalties/git-workshops documentation built on July 3, 2022, 12:53 p.m.