-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14-supplemental-rstudio.html
104 lines (102 loc) · 7.14 KB
/
14-supplemental-rstudio.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title>Software Carpentry: Version Control with Git</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-theme.css" />
<link rel="stylesheet" type="text/css" href="css/swc.css" />
<link rel="alternate" type="application/rss+xml" title="Software Carpentry Blog" href="http://software-carpentry.org/feed.xml"/>
<meta charset="UTF-8" />
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="lesson">
<div class="container card">
<div class="banner">
<a href="http://software-carpentry.org" title="Software Carpentry">
<img alt="Software Carpentry banner" src="img/software-carpentry-banner.png" />
</a>
</div>
<article>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<a href="index.html"><h1 class="title">Version Control with Git</h1></a>
<h2 class="subtitle">Using Git from RStudio</h2>
<section class="objectives panel panel-warning">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-certificate"></span>Learning Objectives</h2>
</div>
<div class="panel-body">
<ul>
<li>Understand how to use Git from RStudio.</li>
</ul>
</div>
</section>
<p>Since version control is so useful when developing scripts, RStudio has built-in integration with Git. There are some more obscure Git features that you still need to use the command-line for, but RStudio has a nice interface for most common operations.</p>
<p>RStudio let’s you create a <a href="https://support.rstudio.com/hc/en-us/articles/200526207-Using-Projects">project</a> associated with a given directory. This is a way to keep track of related files. One of the way to keep track of them is via version control! To get started using RStudio for version control, let’s make a new project:</p>
<p><img src="fig/RStudio_screenshot_newproject.png" /><br /> </p>
<p>This will pop up a window asking us how we want to create the project. We have some options here. Let’s say that we want to use RStudio with the planets repository that we already made. Since that repository lives in a directory on our computer, we’ll choose “existing directory”:</p>
<p><img src="fig/RStudio_screenshot_existingdirectory.png" /> </p>
<aside class="callout panel panel-info">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-pushpin"></span>Do you see a “verson control” option?</h2>
</div>
<div class="panel-body">
<p>Although we’re not going to use it here, there should be a “version control” option on this menu. That is what you would click on if you wanted to create a project on your computer by cloning a repository from github. If that option is not present, it probably means that RStudio doesn’t know where your git executable is. See <a href="https://stat545-ubc.github.io/git03_rstudio-meet-git.html">this page</a> for some debugging advice.</p>
</div>
</aside>
<p>Next, RStudio will ask which existing directory we want to use. Click “browse” to navigate to the correct directory on your computer, then click “create project”:</p>
<p><img src="fig/RStudio_screenshot_navigateexisting.png" /> </p>
<p>Ta-da! Now you have an R project containing your repository. Notice the vertical “Git” menu that is now on the menu bar. This means RStudio has recognized that this directory is a git repository, so it’s giving you tools to use Git:</p>
<p><img src="fig/RStudio_screenshot_afterclone.png" /> </p>
<p>To edit the files in your repository, you can click on them from the panel in the lower right. Let’s add some more information about pluto:</p>
<p><img src="fig/RStudio_screenshot_editfiles.png" /> </p>
<p>We can also use RStudio to commit these changes. Go to the git menu and click “commit”:</p>
<p><img src="fig/RStudio_screenshot_commit.png" /> </p>
<p>This will bring up a screen where you can select which files to commit (check the boxes in the “staged” column) and enter a commit message (in the upper right). The icons in the “status” column indicate the current status of each file. You can also see the changes to each file by clicking on its name. Once everything is the way you want it, click “commit”:</p>
<p><img src="fig/RStudio_screenshot_review.png" /> </p>
<p>You can push these changes by selecting “push” from the Git menu. There are also options there to pull from a remote version of the repository, and view the history:</p>
<p><img src="fig/RStudio_screenshot_history.png" /> </p>
<aside class="callout panel panel-info">
<div class="panel-heading">
<h2><span class="glyphicon glyphicon-pushpin"></span>Are the push/pull commands greyed out?</h2>
</div>
<div class="panel-body">
<p>If this is the case, it generally means that RStudio doesn’t know the location of any other version of your repository (i.e. the one on Github). To fix this, open a terminal to the repository and enter the command: <code>git push -u origin master</code>. Then restart RStudio.</p>
</div>
</aside>
<p>If we click on “history”, we can see a pretty graphical version of what <code>git log</code> would tell us:</p>
<p><img src="fig/RStudio_screenshot_viewhistory.png" /> </p>
<p>RStudio creates some files that is uses to keep track of your project. You generally don’t want to track these, so adding them to your .gitignore file is a good idea:</p>
<p><img src="fig/RStudio_screenshot_gitignore.png" /> </p>
<p>There are many more features buried in the RStudio git interface, but these should be enough to get you started!</p>
</div>
</div>
</article>
<div class="footer">
<a class="label swc-blue-bg" href="http://software-carpentry.org">Software Carpentry</a>
<a class="label swc-blue-bg" href="https://github.com/swcarpentry/git-novice">Source</a>
<a class="label swc-blue-bg" href="mailto:[email protected]">Contact</a>
<a class="label swc-blue-bg" href="LICENSE.html">License</a>
</div>
</div>
<!-- Javascript placed at the end of the document so the pages load faster -->
<script src="http://software-carpentry.org/v5/js/jquery-1.9.1.min.js"></script>
<script src="css/bootstrap/bootstrap-js/bootstrap.js"></script>
<script src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-37305346-2', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>