diff --git a/github_resources.Rmd b/github_resources.Rmd index 1c3d06867..abb90c74c 100755 --- a/github_resources.Rmd +++ b/github_resources.Rmd @@ -20,7 +20,9 @@ Ok, not satisfied with fixing typos on GitHub? Ready to work locally and move co To get comfortable with Git, start with this basic workflow in which you will be pulling from and pushing to *your* repo on GitHub. Just you, no collaboration: +
![](images/git/no-branch.png) +
The [Connect RStudio to Git and GitHub](https://happygitwithr.com/rstudio-git-github.html){target="_blank"} chapter of *Happy Git* will get you set up: you will create a repo on GitHub, clone the repo into an RStudio project, and practice making changes. @@ -40,18 +42,28 @@ It's not considered good practice to commit too often, but as a beginner, it's u Once you've comfortable with the workflow described above, you're ready to start branching. The process is quite similar whether you're working on your own repo or someone else's. +
+![](images/git/your-repo.jpeg) +
+ If it's *your* repo, you can follow the steps in [these slides](https://github.com/jtr13/EDAV/blob/master/pdfs/BranchingYourRepo.pdf){target="_blank"}, which provide step-by-step detail on creating a branch, doing work on the branch and then submitting a pull request to merge the changes into origin/master. Or you can follow the steps below, skipping steps 1 and 3. ## 1st PR on another repo with branching +
+![](images/git/pull-request-1.png) +
+ ### Step 1: Fork the upstream repo (once) {-} *Skip this step if you are syncing with your own repo--that is, you created the repo, you're not cloning a fork of someone else's repo.* Let's say you want to contribute to EDAV! Fork [our GitHub repo](https://github.com/jtr13/EDAV){target="_blank"} and then on your own GitHub page, you will see a forked **EDAV** repo under the repositories section. Note, from now on, the term **upstream repository** refers to the original repo of the project that you forked and the term **origin repository** refers to the repo that you created or forked on GitHub. From your respective, both **upstream** and **origin** are remote repositories. +
![](images/git/fork.png) *A fork of jtr13/EDAV* +
### Step 2: Clone origin and create a local repository (once) {-} @@ -79,19 +91,35 @@ When you're ready to start working on something new, create a new branch. **Do n To create a branch, click on the button shown below: +
+ +
![](images/git/newbranch.png) +
+
+ Give your new branch a meaningful name. For example, if you intend to add a faceting example to the histogram chapter, you might call your branch `add_hist_facet`. Leave the "Sync branch with remote" box checked. Thereby you will not only create a local branch but also a remote branch on origin, and the local branch will be set up to track the remote branch. In short, they will be linked and git will take note of any changes on the other. ### Step 5: Work, commit and push {-} When you create a branch following the method in Step 4, you will be automatically switched to the new branch. You can switch branches by clicking on the branch dropdown box to the right of the new branch button. However, be careful doing so. Work that isn't committed, even if it is saved, doesn't belong to a branch so it will move with you as you change branches. This makes it easy to accidentally be on the wrong branch. Check that you are in the right place and as you work keep an eye on changed files in the Git pane. +
![](images/git/gitpane.png) +
+ +
Recall that there are three steps to moving saved work from your working directory to GitHub, represented by the git commands: `add`, `commit`, and `push`. -![](images/Git_step5.png) +
+ +
+![](images/git/add-commit-push.png) +
+ +
In RStudio, to **add**, you simply click the checkbox for each file you have modified in the "staged" column on the left of the Git pane. To **commit**, you just click on the **commit** button under the Git tab. Entering a commit message is mandatory; choose a meaningful description of the code changes. Finally, to push changes to GitHub, click on the **push** button, which is represented by an upward pointing arrow. You can combine multiple commits into one "push". @@ -115,6 +143,11 @@ Another great resource is ["Explore and extend a pull request"](https://happygit ## 2nd-*n*th PR on another repo with branching +
+![](images/git/pull-request-2.png) + +
+ After the first pull request, the process changes a little. We no longer need to fork and clone the repo. What we do need to do though is make sure that our local copy of the repository is up to date with the GitHub version. There is some other cleanup we need to do, so after the first pull request, we'll replace steps #1 - #3 above with the following: ### Step 1: Sync {-} @@ -186,7 +219,13 @@ Skip this step if there's no upstream repo. Yes, it's odd, but once you've forked and cloned the project repo, the copy on GitHub becomes fairly irrelevant. However it's not a bad idea to keep it up to date, if for no other reason than it's disturbing to see messages like the following in your Git pane: +
+ +
![](images/git/your-branch-ahead.png) +
+ +
Thankfully, your fork on GitHub can be updated easily by clicking the green up arrow or entering `git push` in the Terminal. diff --git a/images/Git_step1.PNG b/images/Git_step1.PNG deleted file mode 100644 index c65eaafb2..000000000 Binary files a/images/Git_step1.PNG and /dev/null differ diff --git a/images/Git_step3.PNG b/images/Git_step3.PNG deleted file mode 100644 index 136c77e8e..000000000 Binary files a/images/Git_step3.PNG and /dev/null differ diff --git a/images/Git_step5.png b/images/Git_step5.png deleted file mode 100644 index b416d14b2..000000000 Binary files a/images/Git_step5.png and /dev/null differ diff --git a/images/Git_step5_commit.PNG b/images/Git_step5_commit.PNG deleted file mode 100644 index aa4cf46ad..000000000 Binary files a/images/Git_step5_commit.PNG and /dev/null differ diff --git a/images/git/add-commit-push.png b/images/git/add-commit-push.png new file mode 100644 index 000000000..b854c1282 Binary files /dev/null and b/images/git/add-commit-push.png differ diff --git a/images/git/fork.png b/images/git/fork.png index dfa49d7f9..93044fdfe 100644 Binary files a/images/git/fork.png and b/images/git/fork.png differ diff --git a/images/git/gitpane.png b/images/git/gitpane.png index 720320ec2..f222bf648 100644 Binary files a/images/git/gitpane.png and b/images/git/gitpane.png differ diff --git a/images/git/newbranch.png b/images/git/newbranch.png index ad154a6a5..380c119fa 100644 Binary files a/images/git/newbranch.png and b/images/git/newbranch.png differ diff --git a/images/git/pull-request-1.png b/images/git/pull-request-1.png new file mode 100644 index 000000000..a9dde7279 Binary files /dev/null and b/images/git/pull-request-1.png differ diff --git a/images/git/pull-request-2.png b/images/git/pull-request-2.png new file mode 100644 index 000000000..74f7e0fdc Binary files /dev/null and b/images/git/pull-request-2.png differ diff --git a/images/git/your-branch-ahead.png b/images/git/your-branch-ahead.png index 5e8008dde..96631fb87 100644 Binary files a/images/git/your-branch-ahead.png and b/images/git/your-branch-ahead.png differ diff --git a/images/git/your-repo.jpeg b/images/git/your-repo.jpeg new file mode 100644 index 000000000..b51759daf Binary files /dev/null and b/images/git/your-repo.jpeg differ