Git/Github Workshop I: Get Started
Posted by Jun Zhao
Updated: Feb 7, 2014
Github Workshop 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) Install Git
- Install Git onto your computer
- Set up Git configuration settings
- Create new Github account
- Quick overview of Github
- 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
- 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
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
cd ~/Desktop
will change directory into our 'Users//desktop' directorymkdir git-todo
will create a new folder called 'git-todo' on your Desktopgit init
creates a new repository in ourgit-todo
directory.cd git-todo
changes the directory into thegit-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 doinggit add .
, and if you also need to remove files that were deleted, you dogit 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 repositorygit-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
.
- 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 thegit_workshop_test
repository here. - Change directory into the repo via
cd git_workshop_test
- Open up the
assignment.md
file, and follow instructions there.
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 substantial, 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
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.
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).
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.
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.
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!
- Git Basics 1
- Viewing The Commit History
- Undoing Things
- Remotes
- Branches
- Merging
- Branch Management
- Workflows
- Rebasing
Interested in Becoming a Data Scientist?
Then you will want to apply to the NYC Data Science Academy. Classes starting soon.
Jun Zhao
View all articlesTopics from this blog: NYC NYC Open Data Meetup data
Subscribe Here
Posts by Tag
- Meetup (101)
- data science (68)
- Community (60)
- R (48)
- Alumni (46)
- NYC (43)
- Data Science News and Sharing (41)
- nyc data science academy (38)
- python (32)
- alumni story (28)
- data (28)
- Featured (14)
- Machine Learning (14)
- data science bootcamp (14)
- Big Data (13)
- NYC Open Data (12)
- statistics (11)
- visualization (11)
- Hadoop (10)
- hiring partner events (10)
- D3.js (9)
- Data Scientist (9)
- NYCDSA (8)
- Web Scraping (8)
- Career (7)
- Data Scientist Jobs (6)
- Data Visualization (6)
- Hiring (6)
- Open Data (6)
- R Workshop (6)
- APIs (5)
- Alumni Spotlight (5)
- Best Bootcamp (5)
- Best Data Science 2019 (5)
- Best Data Science Bootcamp (5)
- Data Science Academy (5)
- Demo Day (5)
- Job Placement (5)
- NYCDSA Alumni (5)
- Tableau (5)
- alumni interview (5)
- API (4)
- Career Education (4)
- Deep Learning (4)
- Get Hired (4)
- Kaggle (4)
- NYC Data Science (4)
- Networking (4)
- Student Works (4)
- employer networking (4)
- prediction (4)
- Data Analyst (3)
- Job (3)
- Maps (3)
- New Courses (3)
- Python Workshop (3)
- R Shiny (3)
- Shiny (3)
- Top Data Science Bootcamp (3)
- bootcamp (3)
- recommendation (3)
- 2019 (2)
- Alumnus (2)
- Book-Signing (2)
- Bootcamp Alumni (2)
- Bootcamp Prep (2)
- Capstone (2)
- Career Day (2)
- Data Science Reviews (2)
- Data science jobs (2)
- Discount (2)
- Events (2)
- Full Stack Data Scientist (2)
- Hiring Partners (2)
- Industry Experts (2)
- Jobs (2)
- Online Bootcamp (2)
- Spark (2)
- Testimonial (2)
- citibike (2)
- clustering (2)
- jp morgan chase (2)
- pandas (2)
- python machine learning (2)
- remote data science bootcamp (2)
- #trainwithnycdsa (1)
- ACCET (1)
- AWS (1)
- Accreditation (1)
- Alex Baransky (1)
- Alumni Reviews (1)
- Application (1)
- Best Data Science Bootcamp 2020 (1)
- Best Data Science Bootcamp 2021 (1)
- Best Ranked (1)
- Book Launch (1)
- Bundles (1)
- California (1)
- Cancer Research (1)
- Coding (1)
- Complete Guide To Become A Data Scientist (1)
- Course Demo (1)
- Course Report (1)
- Finance (1)
- Financial Data Science (1)
- First Step to Become Data Scientist (1)
- How To Learn Data Science From Scratch (1)
- Instructor Interview (1)
- Jon Krohn (1)
- Lead Data Scienctist (1)
- Lead Data Scientist (1)
- Medical Research (1)
- Meet the team (1)
- Neural networks (1)
- Online (1)
- Part-time (1)
- Portfolio Development (1)
- Prework (1)
- Programming (1)
- PwC (1)
- R Programming (1)
- R language (1)
- Ranking (1)
- Remote (1)
- Selenium (1)
- Skills Needed (1)
- Special (1)
- Special Summer (1)
- Sports (1)
- Student Interview (1)
- Student Showcase (1)
- Switchup (1)
- TensorFlow (1)
- Weekend Course (1)
- What to expect (1)
- artist (1)
- bootcamp experience (1)
- data scientist career (1)
- dplyr (1)
- interview (1)
- linear regression (1)
- nlp (1)
- painter (1)
- python web scraping (1)
- python webscraping (1)
- regression (1)
- team (1)
- twitter (1)