Git/Github Workshop I: Get Started

Avatar
Posted on Feb 7, 2014

Slides: 

---------------------------------------------

Meetup Announcement:

Speaker: There will be 7 instructors for this workshop. Each of us will assist a group of attendants to go through the steps.

Vivian Zhang is organizer of NYC Open Data meetup. She is CTO of a data analytic consulting firm---SupStat Inc.

Amanda Himmelstoss is a recent graduate of the Flatiron School; she works at Blopboard, a social polling platform.

Michael Polycarpou is a ruby on rails developer in one of the startup in NYC. He previously studied EE and love work on hardware design.

David Bella is a ruby on rails developer at XO group. He got Computer Science bachelor degree earlier.

Manley Brendan is working for Running through as a web developer. He got bachelor degree from English major.

Ian Miller is a Ruby developer based in NYC, and has a background in renewable energy project development in developing economies.

Ivan Brennan is a Ruby developer and musician interested in open source collaboration.

Outline:

We will walk you through the basic concept of github, then everyone will be assigned a group and your own TA and learn

1. how to download other people's repositories
2.how to push your own codes to your own repositories.

We will cover five main git commands: git clone,git init, git add, git commit, git push

Preparation:

Please install your git before you come and try to install it. http://git-scm.com/download/mac

---------------------------------------------

Other Useful Info Link:

Code History and more details: https://github.com/irmiller22/git_workshop/blob/master/git_workshop.md

Git Workshop

1. Goals:

1) Install Git

  • Install Git onto your computer
  • Set up Git configuration settings

2) Create a Github Account

  • Create new Github account
  • Quick overview of Github

3) Create Repository

  • Learn how to create own repository on Github
  • Initialize repository on computer
  • Set remote repository to Github repo URL
  • Add contents of new repository to commit
  • Push up to master branch of Github repository

4) Cloning a Repository

  • Clone code from Github
  • Create new branch
  • Change code around a bit
  • Learn how to add files to staging area
  • Commit on new branch
  • Push code back to Github

2. First Steps:

1) Install Git:

Go to `http://git-scm.com/downloads`
Follow instructions regarding Git installation (should be included in Git download package)
Set up your Git configuration settings via instructions at `https://help.github.com/articles/set-up-git`
IMPORTANT: When configuring your Git email settings, MAKE SURE IT MATCHES THAT OF YOUR GITHUB ACCOUNT
EMAIL / EMAIL YOU ARE PLANNING TO USE FOR GITHUB ACCOUNT
Ignore the `Password Caching` session for now - you can choose to do this later.

2) Create New Github Profile:

Go to https://github.com/
Create a new account (username, email, password)
When you confirm your account, it will redirect to the home page
Click on the '+' sign next to your username in top right
Select 'New Repository' 
Give the repository the name 'git-todo'

3) Open terminal and follow instructions:

cd ~/Desktop
mkdir git-todo
cd git-todo

touch README.md
git init
git add README.md
git commit -m "initial commit"
git remote add origin <paste http:// link here from Github>
git push origin master

What Happened?

  • cd ~/Desktop will change directory into our 'Users//desktop' directory
  • mkdir git-todo will create a new folder called 'git-todo' on your Desktop
  • git init creates a new repository in our git-todo directory. cd git-todo changes the directory into the git-todo directory. Think of it as going down one level.
  • touch README.md generates a markdown file that is called README.
  • git init initializes, or generates, a new .git file. Think of a .git file as the memory store at the root of a directory. The logic that stores your repository data as well as the synchronization between your remote repositories is encapsulated in this .git file.
  • Before you can commit new files, you have to "stage" them by adding them to a staging directory. You do this by git add README.md. You can also add all new/updated files in current directory by doing git add ., and if you also need to remove files that were deleted, you do git add -A
  • Once all the previous steps are finished, you commit the staging file via `git commit -m "initial commit".
  • In order to push these files up to your Github account, you need to create a repository on Github.com
  • Go to the main Github page, click on the '+' sign, and select New Repository. Then name the repository git-todo. Then once you have created the repository, copy the HTTPS clone URL in the middle of the screen.
  • Add your remote via git remote add origin https://github.com/<your-username>/git-todo.git
  • Finally, push up to your remote via git push origin master.

3. Next Steps:

  • In this next step, we will clone a repository to our desktop, modify the file contents inside of the repository, commit those changes, and push back up to the solutions branch of the Github repository.
  • Go to https://github.com/irmiller22/git_workshop_test.
  • FORK this repository -- once the page reloads, the URL for your repository should be https://github.com/<your-username>/git_workshop_test.
  • Clone your git_workshop_test repository via the HTTPS clone url option in the lower right hand corner of the Github repository screen.
  • Switch over to your Terminal.
  • If you are not at your Desktop path, change directory via the following command: cd ~/Desktop.
  • Then type in: git clone <paste Github HTTPS URL here>.
  • Once completed, type ls to show all files/folders on your Desktop directory. You should see the git_workshop_test repository here.
  • Change directory into the repo via cd git_workshop_test
  • Open up the assignment.md file, and follow instructions there.

4. Cloning:

cd into a the directory you want your project to live in.

On Github, go to the repository you want to contribute to and copy the link on the right hand side of the page.

Back in terminal, and type: git clone <paste http:// link here from Github>

(Note, if this project is something sustantial, say an open source project that you would like to contribute to, it's best practices to Fork the repo to your page and then clone that fork. A fork is basically copying and pasting the repo.)

Once you've cloned the repo, make the changes you want and then, just like when you initialized a new repo above, stage, commit, and push your changes:

git add <file you've changed>
git commit -m "these are the changes I've made"
git push origin master

5. Branching:

Another best practice technique is to make every body of work a separate branch. So far, we've been pushing to the master branch. You can create your own branching off of the master branch and do you work on that.

While on master, before you begin working, type: git checkout -b <your-branch-name>

Do your work on this branch, and while on this branch, be sure, like above to stage, commit, and, if you want your teammates to see your work, push your changes up to Github on your new branch:

git add <file you've changed>
git commit -m "these are the changes I've made"
git push origin <your-branch-name>

Note the last command is pushing the changes up to your new branch, not master.

6. Merging

When you're done with your work on your new branch, you may want to merge it into master. There are two ways to do this, either locally (through git on your computer) or remotely (on Github).

7. Locally

Move onto the branch that you want to merge into, in this case, master: git checkout master. Then, merge your new branch into master: git merge <your-branch-name> Now, master is up to date with your changes on your local repo, and you can push them up to Github.

8. On Github

One arguably better way to handle merging when dealing with a project that multiple people work on is to do all of your work on your new branch, push it up to Github, and then submit a Pull Request on the site. Here, others can see the merge, and Github can check to make sure there aren't any conflicts.

9. More Commands

Here are some other commands to go along with the basic ones we've already covered:

git status: at any point of your work, if you want to see the status of your repo, type git status when you're within your project directory to see which files are staged or unstaged.

git pull: when you're working with other people on a project that's living on Github, most likely they'll be making changes to the code and pushing it up. To bring those changes down to your local repo (on your computer), you will need to pull them.

git stash: let's say you've made changes since then that you don't want anymore. Instead of going into your text editor and manually finding the change, you can stash them and they'll be deleted. Your file will go back to how it was when it was staged last. This is handy, but make sure you absolutely want to do away with your changes before you do this!

10. OTHER RESOURCES:

1) Getting Started

2) Basics of Git

3) Additional Resources

 

 

 

About Author

Related Articles

Leave a Comment

No comments found.

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags

#python #trainwithnycdsa 2019 airbnb Alex Baransky alumni Alumni Interview Alumni Reviews Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Best Data Science Bootcamp 2020 Best Ranked Big Data Book Launch Book-Signing bootcamp Bootcamp Alumni Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data science jobs Data Science Reviews Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Hiring Partners Industry Experts Instructor Blog Instructor Interview Job Job Placement Jobs Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research Meet the team meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Online Online Bootcamp Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest Ranking recommendation recommendation system regression Remote remote data science bootcamp Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Switchup Tableau team TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp