Skip to content

github tutorial Youtube

Cecile Hannay edited this page Oct 28, 2021 · 20 revisions

Youtube Video:

https://www.youtube.com/watch?v=RGOj5yH7evk

Some terminology

git / version control = way to track code changes

repo = folder where the project is kept

git = tool that tracks the changes over time

githib = website where we keep all our repo

git commands

  • clone -> bring a repo hosted somewhere (for instance on github) into a folder on your local machine
  • add -> track your files and changes in git
  • commit -> save your files in git
  • push -> upload git to a remote repo (like github)
  • pull -> download changes from remote repo to local machine

github repo

repo = project that contains all my files for a specific project

To create new repo:

Screen Shot 2021-10-05 at 4 12 29 PM

Select: README, LICENSE, and .gitignore

(It is recommended that every repository include a README, LICENSE, and .gitignore)

About README.md

This is a file that describe what the project is about.

You can create the README.md file directly on github or you can create it locally.

create a new repository on the command line

echo "# demo-repo2" >> README.md

git init

git add README.md

git commit -m "first commit"

git branch -M main

git remote add origin https://github.com/cecilehannay/demo-repo2.git

git push -u origin main

push an existing repository from the command line

git remote add origin https://github.com/cecilehannay/demo-repo2.git

git branch -M main

git push -u origin main

Local repo

To clone locally:

git clone git@github.com:cecilehannay/github-tutorial.git

cd github-tutorial

The directory github-tutorial contains a file .git that contains all the changes recorded in the history of the repo.

Modify a file locally

Edit README.md

git status

shows the files that haven't been saved yet in the local repo (it can be files that have been modified

modified:

or files that haven't been saved in the repo)

Untracked files:

stage the file *

git add .

stage the files with git and they are ready to be committed.

commit

git commit -m "Modified the README.md on local repo" -m "Description of the change "

Now the changes is on the local repo

push the changes on the remote repo (github)

Check what the origin is:

git remote -v

returns

origin git@github.com:cecilehannay/github-tutorial.git (fetch)

origin git@github.com:cecilehannay/github-tutorial.git (push)

git push origin master Origin = the location of our git repo Master = the branch we want to push to

TO avoid to add each time "origin master"

Enter the first time

git push -u origin master

and after

git push

start a repo locally

To make a directory a git

Summary of workflow:

![](Screen Shot 2021-10-06 at 4 57 52 PM)

Git branching

We are on the main branch. This is the default branch on the repo. If only one branch, this will be the branch

![](Screen Shot 2021-10-28 at 2 22 38 PM)

If we are have several branches, it starts looking like a tree:

Screen Shot 2021-10-28 at 2 26 21 PM

Let's say we want to create a new branch called "feature branch" At first the code will be exactly the same on the main branch and the feature branch. But as we make changes on the feature branch, The other branch don't see each other. We want to have a feature branch to make our changes before bringing them back to the main branch.

Very useful, for instance, if we have a bug on the main branch. We create another branch called the "hot fix branch" ![](Screen Shot 2021-10-28 at 2 30 34 PM)

Let's do an example:

Define ssh keys if needed

Generate a key locally

ssh-keygen -t rsa -b 4096 -C "hannay@ucar.edu"

+> this generates 2 keys private and public

Clone this wiki locally