Git
What is version control?
Version control allows you to maintain track of your work and investigate the changes you’ve made, whether it’s data, code scripts, notes, or anything else. If you save numerous files with names like Dissertation script 25thFeb.R, Dissertation script 26thFeb.R, and so on, you’re probably already using version control. This method will result in tens or hundreds of identical files, making it difficult to compare various versions directly and sharing across collaborators. Version control is considerably smoother and easier to apply using version control software like Git. When you put your files on an online platform like Github, you have an online backup of your work, which is advantageous to both you and your colleagues.
Git utilizes the command line to conduct more complex activities, and we recommend that you go through the additional materials we’ve included at the conclusion of the lesson to obtain a better understanding of Git. But, in the meanwhile, here’s a quick guide to syncing RStudio with Github so you can start utilizing version control right now.
What are the benefits of using version control?
Having a GitHub repo makes it simple to maintain track of collaborative and personal projects: all files required for certain studies can be kept together, and users may contribute code, graphs, and other materials as the projects progress. Each file on GitHub has a history, making it simple to see how it has changed over time. You may go through other people’s code, provide comments on specific lines or the entire document, and make suggestions for improvements. GitHub allows you to give tasks to various users in collaborative projects, making it apparent who is accountable for which element of the analysis. You can also ask certain users to review your code. For personal projects, version control allows you to keep track of your work and easily navigate among the many versions of the files you create, whilst also maintaining an online backup.
GitHub
Get start
You’ll need a GitHub account and Internet connection to get started. You don’t need to know how to write, utilize the command line, or install Git to use this tool. If you have any questions about any of the terms mentioned in this tutorial, see the glossary for further information.
Creating a repository
Typically, a repository is used to organize a single project. Repositories may hold whatever your project need, including folders and files, photos, videos, spreadsheets, and data sets. README files, which include information about your project, are frequently included in repositories. The Markdown language is used to write README files. This guide sheet will help you get started with Markdown syntax. When you create a new repository on GitHub, you may add a README file at the same time. Other typical choices, like as a license file, are available on GitHub, but you do not need to pick any of them right now.
In the upper-right corner of any page, use the drop-down menu, and select New repository.
In the Repository name box, enter your repository name.
In the Description box, write a short description.
Select Add a README file.
Select whether your repository will be Public or Private.
Click Create repository.
Creating a branch
Branching allows you to have many versions of a repository open at the same time.
Your repository contains one main branch by default, which is considered the definitive branch. In your repository, you may construct other branches off of main. Branches allow you to work on many versions of a project at the same time. When you want to add new features to a project without affecting the primary source of code, this is useful. Work done on multiple branches will not appear on the main branch until you combine it, which we will discuss later in this tutorial. Before submitting changes to main, you can experiment with branches and make changes.
Click the Code tab of your repository.
Click the drop down at the top of the file list that says main.
Type a branch name,
readme-edits
, into the text box.Click Create branch: readme-edits from main.
Main and readme-edits are now your two branches. They appear to be identical at the moment. You’ll then make changes to the new branch.
Making and committing changes
GitHub took you to the code page for your new readme-edits branch, which is a clone of main, when you established a new branch in the previous stage.
Changes to the files in your repository can be made and saved. Commits are the name for stored changes on GitHub. A commit message is a statement of why a certain change was done that is connected with each commit. Other contributors can understand what you’ve done and why you’ve done it by looking at your commit messages.
Under the
readme-edits
branch you created, click the README.md file.Click to edit the file.
In the editor, write a bit about yourself. Try using different Markdown elements.
In the Commit changes box, write a commit message that describes your changes.
Click Commit changes.
These modifications will only affect the README file on your readme-edits branch, therefore this branch now has content distinct from main.
Opening a pull request
You may open a pull request now that you have modifications in a branch off of main.
On GitHub, pull requests are the lifeblood of cooperation. When you submit a pull request, you’re proposing your modifications and asking for someone to evaluate, pull in, and integrate your contribution into their branch. Pull requests display content discrepancies, or diffs, from both branches. Different hues represent changes, additions, and subtractions.
Even before the code is ready, you may post a pull request and start a debate as soon as you commit.
You may ask for comments from individual people or teams in your pull request message by utilizing GitHub’s @mention functionality, whether they’re down the hall or 10 time zones away.
You may even open pull requests and merge them in your own repository. It’s an excellent method to get a feel for the GitHub workflow before diving into larger projects.
Click the Pull requests tab of your repository.
Click New pull request
In the Example Comparisons box, select the branch you made,
readme-edits
, to compare withmain
(the original).Look over your changes in the diffs on the Compare page, make sure they’re what you want to submit.
Click Create pull request.
Give your pull request a title and write a brief description of your changes. You can include emojis and drag and drop images and gifs.
Optionally, to the right of your title and description, click the next to Reviewers. Assignees, Labels, Projects, or Milestone to add any of these options to your pull request. You do not need to add any yet, but these options offer different ways to collaborate using pull requests. For more information, see “About pull requests.”
Click Create pull request.
Your collaborators can now review your edits and make suggestions.
Merging your pull request
You’ll merge your readme-edits branch into the main branch in this final step. The modifications in your readme-edits branch will be merged into main when you merge your pull request.
A pull request may occasionally bring code modifications that clash with the current code on main. If there are any disputes, GitHub will notify you and block you from merging until the problems are fixed. You may either settle the disputes with a commit or use comments in the pull request to discuss them with your teammates.
Click Merge pull request to merge the changes into
main
.
Click Confirm merge. You will receive a message that the request was successfully merged and the request was closed.
Click Delete branch. Now that your pull request is merged and your changes are on
main
, you can safely delete thereadme-edits
branch. If you want to make more changes to your project, you can always create a new branch and repeat this process.