Skip to content

Latest commit

 

History

History
436 lines (248 loc) · 12 KB

day1.md

File metadata and controls

436 lines (248 loc) · 12 KB

Sciware

Intro to Github

https://github.com/flatironinstitute/learn-sciware-dev/tree/master/15_IntroGithub

Rules of Engagement

Goal:

Activities where participants all actively work to foster an environment which encourages participation across experience levels, coding language fluency, technology choices*, and scientific disciplines.

*though sometimes we try to expand your options

Rules of Engagement

  • Avoid discussions between a few people on a narrow topic
  • Provide time for people who haven't spoken to speak/ask questions
  • Provide time for experts to share wisdom and discuss
  • Work together to make discussions accessible to novices
(These will always be a work in progress and will be updated, clarified, or expanded as needed.)

Zoom Specific

  • If comfortable, please keep video on so we can all see each other's faces.
  • Ok to break in for quick, clarifying questions.
  • Use Raise Hand feature for new topics or for more in-depth questions.
  • Please stay muted if not speaking. (Host may mute you.)
  • We are recording. Link will be posted on #sciware Slack.

Future Sessions

  • Tomorrow: Github Part 2: collaboration
  • July 8: Intro to IDEs and Debugging
  • Suggest topics and vote on options in #sciware Slack

Today's Agenda

  • What is Git and GitHub?
  • Setting up git and GitHub on your computer
  • Getting code off of GitHub
  • Putting code onto GitHub

Intro to Git and GitHub

Version control

  • keeps track of history of one or more files
  • helps with backup and collaboration
  • makes it easier to combine changes to the same file

an open-source, distributed, command-line, version-control tool

  • released in 2005 by Linus Torvalds for developing Linux, as an alternative to older tools (CVS, svn)
  • now the dominant tool for academic and industry software development
  • distributed: no central server, every repo is fully functional, independent, and can "sync" with any other

GitHub

  • A central website for storing and sharing git repositories
  • Started in 2008 as a freemium service, now owned by Microsoft
  • Provides repository management, permissions, collaboration tools, CI, etc.

Setting up GitHub on your Computer

Make sure git is installed

 > git version
git version 2.30.1

If this returns an error, please raise your hand and someone can help you in a breakout room.

Setting your name in Git

See what name is currently set

 > git config --global user.name

Set your name

 > git config --global user.name "Mona Lisa"

Setting your email address

See what email address is currently set

 > git config --global user.email

Set an email address

 > git config --global user.email "[email protected]"

(Ideally set to the same email address you used for Github.)

Setup SSH

Generate an SSH key and copy it to the clipboard

 > ssh-keygen -t ed25519
> cat ~/.ssh/id_ed25519.pub

It is easiest to leave the password blank.

Add the SSH key to GitHub

  • On Github:
    • Profile Photo > Settings > SSH and GPG keys > New SSH Key

Settings screenshot

SSH Keys screenshot

Add the SSH key to GitHub

  • Title should refer to the computer on which the key was generated.

  • Paste key into text box.

Setup Git's default text editor

  • So that you don't get stuck in vi:
 > git config --global core.editor "nano -w"
  • How to set up your favorite editor with Git:

https://git-scm.com/book/en/v2/Appendix-C%3A-Git-Commands-Setup-and-Config#ch_core_editor

Questions?

Getting code from GitHub onto your computer

Clone graphic

GitHub Jargon

Clone graphic
  • Folder containing the code
  • - repository or repo, for short
  • "Download the code"
  • - clone the repo
  • Your computer harddrive
  • - local

Download the code to your computer in GitHub-ese is
Clone the Repo to your local

Clone the repo

Clone button screenshot

Clone the repo (continued...)

  • In a Terminal window, clone the repo:
 > git clone [email protected]:flatironinstitute/sciware15-git-intro
> cd sciware15-git-intro

A folder will be created containing all of the files in the repo.

The folder name will be the repo name.

What does git clone do?

Using the git clone command connects the folder to the repo on GitHub in case you ever wanted to interact with it later.

  • It generates hidden folder .git
 > ls -a
  • It also saves the URL to the repo and names it origin
 > git remote -v
origin  [email protected]:flatironinstitute/sciware15-git-intro (fetch)
origin  [email protected]:flatironinstitute/sciware15-git-intro (push)

Questions?

Clone graphic

Activity

Find a repo and clone it to your computer

https://github.com/explore

Survey

Putting code on GitHub

Push to remote graphic

Make a project folder

 > mkdir silly_project
> cd silly_repo
> touch silly_code.py
> touch silly_funct.py

Local graphic

Create a repo on Github

remote graphic
  • Go to your homepage on Github
  • Click the Repositories tab
  • Click the green New button
  • Name the repository silly_repo

Initialize the directory to use with Github

 > git init
 > git status

Local graphic

Name the primary branch main

It's possible to have multiple branches of the code where different things are being worked on.

The primary branch is usually called main.

> git branch -M main
> git status

Notice:

  • branch name
  • silly_file.txt is in red and is untracked

Specify which files that you want to transfer

Use the git add command to specify exactly which files you want to transfer to Github.

> git status
> git add silly_file.txt
> git status

Notice:

  • silly_file.txt is now green
  • silly_file.txt needs to be committed

Save the changes

Use the git commit to save the local changes.

Add a commit message to document the changes.

Launch a text editor where you can type the commit message:

 > git commit

Alternatively, you can commit directly from the command line:

  > git commit -m "add silly file"
  > git status

Connect the folder to Github

Use git remote add to provide the URL to the Github repo.

The repo that is in your personal profile is usually called origin

> git remote -v 
> git remote add origin [email protected]:kelle/silly_project.git
> git remote -v

Upload the folder contents to Github

Use the git push command to upload the committed changes to the Github repo.

 > git push origin main

Push to remote graphic

Check Github

silly_file.txt should now be in the repo on the Github website.

Push to remote graphic

Questions?

Push to remote graphic

Activity

Put one of your projects into a new Github repo

Troubleshooting

  • Find Github buddies
    • The best way to figure things out is by asking folks for help

Octocat buddies

Troubleshooting

  • Avoid problems by keeping track of the state of your local.
  • Inspect git status before and after every command until you gain confidence

github status screenshot

https://medium.com/@kenwarner/command-line-ux-matters-too-improve-your-git-status-colors-170de858953d

Troubleshooting

  • There are many resources for common git and Github problems on the internet.
    • Consider discussing with a buddy before copy/pasting.

github status screenshot

Tomorrow

Using Github to collaborate

Push to the fork graphic

Survey