Git for Mere Mortals¶
Goal¶
This tutorial will teach the the basics of git using GitHub. You will learn how to create a repository and interact with the GitHub environment through an internet browser and desktop client. The tutorial will briefly introduce some advanced topics.
You can follow along with the rest of this tutorial on your own, or with the corresponding YouTube Video Link will be added once it’s live.
Cloning, Branching, & Versioning¶
Description:
In this step, you will learn more advanced skills including cloning a repo, the difference between branching and forking, and how to submit and accept pull requests.
Clone a repo¶
Online
- Click the down arrow “Clone or download”
- Click “Open in Desktop”
- Select where to save it
- Create a folder for GitHub repos on your computer locally
Commit¶
Online
- Create a file by clicking “Create a new file”
- Name file (/name)
- Write commit message
- Press “Commit”
Desktop
- Create a file and put it in your local GitHub repo
- Open Desktop
- Fetch origin
- Write a commit message & hit commit
- Push to origin
- See changes on the repo online
Tip
fetch & pull origin (see changes you’ve made online)
Version Control¶
Online
- Click on file
- Click “History”
Desktop
- Go to repository
- Go to branch
- Go to “Changes”
Revert to Previous Version¶
Online
- Find the commit you want to revert back to
- Click on the unique ID (a series of numbers)
- Download the zip file
Note
You can add comments to specific changes by putting the mouse on the change and clicking the “+” button
Desktop
- Click on history
- Right click on the last commit you want to rever to and select “Revert This Commit”
- this essentially “undoes” the commit made
Create a branch¶
Online
- Select the down arrow on the repository page that says “Branch:master”
- Create a new branch name
OR
- Add new file or edit existing file.
- Write a commit message.
- Select “Create a new branch”
Desktop
- Fetch & pull origin
- Select “Current branch”, make a “New Branch”, “Publish Branch” (you can see that it has been made online)
Pull request¶
Online
- From your branch, create a new file
- Commit file to your branch
- Hit “Compare & pull request”
- Go to pull requests
- “Merge pull request”
- Delete branch
- See it on the master branch
Desktop
- Fetch & pull origin
- Select “Current branch”, make a “New Branch”, “Publish Branch” (you can see that it has been made online)
OR
- Select a branch if one has already been made
- Make changes to a file
- Write a commit message & commit
- Push to origin
- “Create a pull request” (takes you back online)
Tip
pull requests are great to get feedback from collaborators before making a change
Note
that you can always revert back to a previous version
Exercise: Why would pull requests be important?
Merge¶
Online
- Go to “Pull requests”
- Select down arrow of “Merge pull request”
- Merge, Squash, or Rebase OR ignore
- Leave comment if need be
- Close pull request
Fork¶
- Go to a new repository
- Click fork
- Save to personal repository.
- Clone to Desktop.
- Interact via online or in Desktop.
- If want to make suggestions, can create a pull request.
Etc.¶
- Versioning
- Go to “Releases”
- Click “Create a new release”
- Tag version: Version #
- Release title: I usually put the date of the release, but any system can work
- Notifications:
- get notified when there is an issue or pull request created
- can also “watch” a repository and get updates
- Badges
- Go find a badge!
- Copy badge code into README:
Fix or improve this documentation
Search for an answer: CyVerse Learning Center
Prerequisites¶
Downloads, access, and services¶
In order to complete this tutorial you will need access to the following services/software
Platform(s)¶
We will use the following CyVerse platform(s):
No CyVerse platforms are needed for this tutorial.
Introduction to Git & GitHub¶
Definitions¶
Git - tool for version control.
GitHub - hosted server that is also interactive.
repo - short for repository; GitHub lets you create a remote repository online.
local - on your personal computer.
clone - copy of a repository that lives locally on your computer. Pushing changes will affect the repository online.
fetch - getting latest changes to the repository on your local computer.
branch - parallel to the master branch; allows you to make changes without affecting the master branch. Changes made on a branch can be merged back to the master.
fork - copy of someone else’s repository stored locally on your account. From forks, you can make pull requests to the master branch.
upstream - primary or master branch of original repository.
downstream - branch or fork of repository.
commit - finalize a change.
push - add changes back to the remote repository.
merge - takes changes from a branch or fork and applies them to the master.
pull request - proposed changes to/within a repository.
issue - suggestions or tasks needed for the repository. Allows you to track decisions, bugs with the repository, etc.
Introduction¶
We will learn how to:
- create a repository
- best practices
- create an issue
- push/pull files
- commit to GitHub
- interact with the GitHub environment
- using the web interface
- using GitHub Desktop
- advanced GitHub
- branching
- forking
- merging
- versioning
GitHub makes it easy to keep track of changes and has a built in version control.
Background¶
GitHub Uses¶
- Version control
- Collaborative projects
- Creating websites
- Teaching tools
- Software development
- Code development
Note
Git is not really for storing or manipulating data, especially large files. But the CyVerse Discovery Environment is a great place to serve, store, and share data.
Fix or improve this documentation
Search for an answer: CyVerse Learning Center