101
Abhishek Gupta @abhiguptame Bangalore Tech Talks: GitHub Hacks

GitHubHacksBangaloreTechTalks

Embed Size (px)

Citation preview

Page 1: GitHubHacksBangaloreTechTalks

Abhishek Gupta@abhiguptame

Bangalore Tech Talks: GitHub Hacks

Page 2: GitHubHacksBangaloreTechTalks

About Me

• B.E. (Information Science) graduate from PESIT, Bangalore

• Campus Hire @ Microsoft

Bangalore Tech Talks: GitHub Hacks

Abhishek Gupta@abhiguptame

More Info: http://www.abhinotes.com

Page 3: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

One Request!• Stop me, If you want me repeat some concepts.

Page 4: GitHubHacksBangaloreTechTalks

Agenda • Version Control System • Git & GitHub Basics • GitHub beyond Master, Branch & Pull Requests• Interesting Facts • Important Links

Bangalore Tech Talks: GitHub Hacks

Page 5: GitHubHacksBangaloreTechTalks

Version Control System

Bangalore Tech Talks: GitHub Hacks

• A version control system (also known as a Revision Control System) is a repository of files, often the files for the source code of computer programs, with monitored access.

Page 6: GitHubHacksBangaloreTechTalks

Version Control System• Without• Local• Centralized• Distributed

Bangalore Tech Talks: GitHub Hacks

What ?

Page 7: GitHubHacksBangaloreTechTalks

Without Version Control Systems• Copy files into another directory• Store or Share files backups by email• Store or Share files by pendrive

Bangalore Tech Talks: GitHub Hacks

Page 8: GitHubHacksBangaloreTechTalks

Local Version Control Systems• Just a local Database• Systems: • Revision Control System

Bangalore Tech Talks: GitHub Hacks

Page 9: GitHubHacksBangaloreTechTalks

What If?

Bangalore Tech Talks: GitHub Hacks

Page 10: GitHubHacksBangaloreTechTalks

Centralized Version Control Systems• A Central Server• The most used for the companies• Systems:• Concurrent Versions System • Team Foundation Server

Bangalore Tech Talks: GitHub Hacks

Page 11: GitHubHacksBangaloreTechTalks

Centralized Version Control Systems

Advantages• Everyone knows to a certain degree what everyone else on the project is doing• Administrators have more control over what everyone can do

Bangalore Tech Talks: GitHub Hacks

Page 12: GitHubHacksBangaloreTechTalks

Centralized Version Control Systems

Disadvantages• If Server goes down, this means nobody can save changes• If HD Server breaks, this means good bye all control version history

Bangalore Tech Talks: GitHub Hacks

Page 13: GitHubHacksBangaloreTechTalks

Distributed Version Control Systems

Bangalore Tech Talks: GitHub Hacks

• Distributed: each client has fully mirror of the repository• Systems:• Git • Mercurial, Bazaar

Page 14: GitHubHacksBangaloreTechTalks

Distributed Version Control Systems

Advantages• Every time someone pulls from the central repository, Git gets a full history of the changes• Most of the functionalities doesn’t need access to some network. So we can work even not connected to the internet• A project can be associated to a more than one remote repository• You can do anything just using the console

Bangalore Tech Talks: GitHub Hacks

Page 15: GitHubHacksBangaloreTechTalks

Distributed Version Control Systems

Disadvantages• Git requires some learning curve to understand its concept• The administrators don’t have control over what happens on each client local repository

Bangalore Tech Talks: GitHub Hacks

Page 16: GitHubHacksBangaloreTechTalks

What is

Bangalore Tech Talks: GitHub Hacks

&

Page 17: GitHubHacksBangaloreTechTalks

• Git is an extremely fast, efficient, distributed version control system used for collaborative development of software. Git was designed and developed by Linus Torvalds.

Bangalore Tech Talks: GitHub Hacks

Page 18: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

• Github is a web-based hosting service for software development projects that use the Git revision control system. Github was founded by Chris Wanstrath and Tom Preston-erner and PJ Hyett.

Page 19: GitHubHacksBangaloreTechTalks

Flow• Installing • Configuring Git with Github• Working locally with Github• Working remotely with Github

Bangalore Tech Talks: GitHub Hacks

Page 20: GitHubHacksBangaloreTechTalks

Installing Git• Installing Git is simple.

Download and follow the steps of installation.• Find detailed installations:• Linux

http://help.github.com/linux-set-up-git/Windows http://help.github.com/win-set-up-git/ OSX http://help.github.com/mac-set-up-git/

Bangalore Tech Talks: GitHub Hacks

Page 21: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Download and Install Git• Once the file is downloaded, open it up and begin the installation process• Just go with the defaults, and then open up Git Bash

Page 22: GitHubHacksBangaloreTechTalks

Configure Username and Email• Each commit to a Git repository will be “tagged” with the username of the person who made the commit• Enter the following commands in Git Bash, one at a time, to set your username and email.• Make sure you remember which email you used – that’ll be the one we’ll

need to use to register for GitHub.• Type git config –list afterward, to make sure your changes were made

Bangalore Tech Talks: GitHub Hacks

Page 23: GitHubHacksBangaloreTechTalks

Common Commands

Bangalore Tech Talks: GitHub Hacks

pwd Displays the path to the current working directoryclear Clears out the commands that you currently have displayed in the CLIls Lists files and folders in the current directoryls –a Lists hidden and unhidden files and folders (“-a” is a flag)ls –al Lists details for hidden and unhidden files and folders (“-l” is a flag)cd Takes you to your home directory. Takes as an argument the directory you want

to visit.cd .. Go up one directorymkdir Makes a directory; takes as an argument the folder you want to maketouch Creates an empty file (argument is the file name)cp Copy; first argument is a file, second argument is the path where you want the

file to be copied. Use the flag “-r” to copy a directory.

rm Remove; argument is the file you want to remove. The flag “-r” can remove a directory.

date Prints today’s date.echo Prints out to the CLI whatever arguments you provide

Page 24: GitHubHacksBangaloreTechTalks

Create a GitHub Account• https://github.com• Enter in a username, email, and password, and click “Sign up for Github”. • Use a .edu address if you’ve got access to one!

Bangalore Tech Talks: GitHub Hacks

Page 25: GitHubHacksBangaloreTechTalks

Git vs. GitHub• Git is local on your computer• GitHub is available via the internet (“remote”)• GitHub allows you to:• Share your repos with others• Access other users’ repositories• Store remote copies of your repositories on GitHub’s server in case something bad happens to the local copies on your computer• You don’t need GitHub to use git

Bangalore Tech Talks: GitHub Hacks

Page 26: GitHubHacksBangaloreTechTalks

Creating a GitHub Repository• Two methods of creating a GitHub repository:• Start a repository from scratch• “Fork” another user’s repository

• https://github.com/YourUserName --> “Create a new repo”• https://github.com/new (if you’re logged into your GitHub

account)• Create a name for the repo; select “Public”; make a brief

description; initialize with a README; and click “Create repository” button.

Bangalore Tech Talks: GitHub Hacks

Page 27: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 28: GitHubHacksBangaloreTechTalks

Creating a Local Copy• Now you need to create a copy of this repository on your computer so that you can make changes to it!• Open Git Bash• Create a directory on your computer to store your copy of the repo• Navigate to this new directory using “cd”

Bangalore Tech Talks: GitHub Hacks

Page 29: GitHubHacksBangaloreTechTalks

Creating a Local Copy• Initialize a local Git repository in this directory with “git init”• Point your local repository at the remote repository you just created on the GitHub server

Bangalore Tech Talks: GitHub Hacks

Page 30: GitHubHacksBangaloreTechTalks

Forking another user’s repo• The second method of creating a repository is to make a copy of someone else’s.• This process is called “forking” and is an important aspect of open-source software development.

Bangalore Tech Talks: GitHub Hacks

Page 31: GitHubHacksBangaloreTechTalks

Clone the Repo• So there’s a copy of the repository in your GitHub account now.• but you still need to make a local copy on your computer.• This is called “cloning”. You can do it with the following command:

Bangalore Tech Talks: GitHub Hacks

Page 32: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Before Cloning

After Cloning

Readme File

Page 33: GitHubHacksBangaloreTechTalks

The Three States

Bangalore Tech Talks: GitHub HacksModified/UntrackedStaged Committed

Page 34: GitHubHacksBangaloreTechTalks

Adding• If you add new files to a local repository (a directory

that’s just housed on your computer, not on the internet) you need to let Git know that they need to be tracked.• This should always be done before committing.

Bangalore Tech Talks: GitHub Hacks

git add . Stages new and modified, without deleted

git add –u Stages modified and deleted, without new

git add –A Stages All

Page 35: GitHubHacksBangaloreTechTalks

Removing

Bangalore Tech Talks: GitHub Hacks

git rm file_name/ Stages a removed file

git rm -r folder_name/

Stages a removed folder

Page 36: GitHubHacksBangaloreTechTalks

Diff

Bangalore Tech Talks: GitHub Hacks

git diff HEAD file_name

Compare the working directory with local repository

git diff file_name Compare the working directory with staging area

git diff --name-status branch_1 branch_2

Compare the branches showing just the status and file name

Page 37: GitHubHacksBangaloreTechTalks

Committing and Pushing• If you want to commit changes to your local repository, you use the following command:

Bangalore Tech Talks: GitHub Hacks

Page 38: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 39: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 40: GitHubHacksBangaloreTechTalks

Branches• Sometimes you’re working on a project with a version that’s being used by a lot of different people• You might not want to edit the version that everyone’s editing – so you can branch off a copy of the repo with the command:

Bangalore Tech Talks: GitHub Hacks

Page 41: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 42: GitHubHacksBangaloreTechTalks

Pull Requests• If you fork someone’s repo or have multiple branches, you will both be working separately• Sometimes you want to merge in your changes with the other branch / repo• To do so, you need to send in a “pull request” (feature of GitHub)

Bangalore Tech Talks: GitHub Hacks

Page 43: GitHubHacksBangaloreTechTalks

Merges• Merge on the current branch changes made on another branch• $ git merge branch_name

Bangalore Tech Talks: GitHub Hacks

Page 44: GitHubHacksBangaloreTechTalks

.gitignore• Its always a good practice to commit onlythose files to GitHub repository that are required. So if you are having a Java project you shouldremove .class files and any other file that have sensitive information e.g. username/password etc.

Bangalore Tech Talks: GitHub Hacks

Page 45: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

•.gitignore file is used to specify which files to exclude from commit.•Here we have excluded all the files that are under .settings and build directory

Page 46: GitHubHacksBangaloreTechTalks

Working remotely with GithubUpdating from a remote repository• Git has two commands to update itself from a remote repository. 

git fetch or git pull

The difference in these two commands in the simplest terms is that, "git pull" does a "git fetch" followed by a "git merge".

Bangalore Tech Talks: GitHub Hacks

Page 47: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 48: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 49: GitHubHacksBangaloreTechTalks

Take a break.•We all deserve it

Bangalore Tech Talks: GitHub Hacks

your career partnerEvent Host Partner

Page 50: GitHubHacksBangaloreTechTalks

GitHub beyond Master, Branch & Pull Requests

Bangalore Tech Talks: GitHub Hacks

Page 51: GitHubHacksBangaloreTechTalks

GitHub++• GitHub For Desktop• GitHub Pages for Website Hosting• GitHub Pages for Project Website

Bangalore Tech Talks: GitHub Hacks

Page 52: GitHubHacksBangaloreTechTalks

GitHub For Desktop

Bangalore Tech Talks: GitHub Hacks

https://desktop.github.com/

Page 53: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 54: GitHubHacksBangaloreTechTalks

GitHub Pages for Website Hosting

• Create a GitHub Repository• username.github.io [eg. abhiguptame.github.io]

• Add (Commit & Push) your website files to the repository [username.github.io]

Bangalore Tech Talks: GitHub Hacks

Page 55: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 56: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 57: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 58: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 59: GitHubHacksBangaloreTechTalks

Using a Custom Domain• Create a new file name CNAME• Yourdomain.com [www.abhinotes.com]

Bangalore Tech Talks: GitHub Hacks

Page 60: GitHubHacksBangaloreTechTalks

Using a Custom Domain• Setup a new A record that points to IP address:• 192.30.252.153 or 192.30.252.154

Bangalore Tech Talks: GitHub Hacks

Page 61: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 62: GitHubHacksBangaloreTechTalks

GitHub Pages for Project Website

• https://pages.github.com/

Bangalore Tech Talks: GitHub Hacks

Page 63: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 64: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 65: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 66: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 67: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 68: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 69: GitHubHacksBangaloreTechTalks

GitHub++• Git Resume• Visit the following repo and Star this project

Bangalore Tech Talks: GitHub Hacks

Page 70: GitHubHacksBangaloreTechTalks

Git Resume

Bangalore Tech Talks: GitHub Hacks

Page 71: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 72: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 73: GitHubHacksBangaloreTechTalks

GitHub++• GitHub For Students (.edu Email Id)

https://education.github.com/pack

Bangalore Tech Talks: GitHub Hacks

Page 74: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 75: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 76: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 77: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 78: GitHubHacksBangaloreTechTalks

Bangalore Tech Talks: GitHub Hacks

Page 79: GitHubHacksBangaloreTechTalks

Interesting Facts:• GitHub, Inc. was originally known as Logical Awesome• Linus Torvalds has himself hosted the Linux kernel source tree on GitHub. And he works very actively on it. @torvalds/linux

Bangalore Tech Talks: GitHub Hacks

Page 80: GitHubHacksBangaloreTechTalks

Interesting Facts:• Approximately two-thirds of the employees at GitHub work remotely.

• GitHub hosts its own products on GitHub. @https://github.com/github

• GitHub was blocked in India for 10 days (31 Dec 2014 -10 Jan 2015).

Bangalore Tech Talks: GitHub Hacks

Page 81: GitHubHacksBangaloreTechTalks

Interesting Facts:

Bangalore Tech Talks: GitHub Hacks

Page 82: GitHubHacksBangaloreTechTalks

ProGit Book• https://github.com/opendream/progit

Bangalore Tech Talks: GitHub Hacks

Page 83: GitHubHacksBangaloreTechTalks

Important Links:• http://git-scm.com/doc• https://help.github.com• http://learn.github.com/p/intro.html• http://gitref.org/index.html• https://try.github.io

Bangalore Tech Talks: GitHub Hacks

Page 84: GitHubHacksBangaloreTechTalks

Questions

•Any Questions?

Page 85: GitHubHacksBangaloreTechTalks

Thank you! @abhiguptame

Bangalore Tech Talks: GitHub Hacks

Page 86: GitHubHacksBangaloreTechTalks

What Next?

djobsHeadStart

Bangalore Tech Talks: GitHub Hacks

Page 87: GitHubHacksBangaloreTechTalks

What is djobsHeadStart?

• A GitHub Project where:• You can request a technology that you want to learn• You can share the resources for requested technology or your interesting hacks.

Bangalore Tech Talks: GitHub Hacks

Page 88: GitHubHacksBangaloreTechTalks

djobsheadstart• https://www.github.com/djobsheadstart• https://github.com/djobsheadstart/LoveToShare• https://github.com/djobsheadstart/RequestToLearn

Bangalore Tech Talks: GitHub Hacks

Page 89: GitHubHacksBangaloreTechTalks

How to request?• Sign in to your GitHub Account• Search “RequestToLearn” • Click on djobsheadstart/RequestToLearn Repo• As Shown in image

Bangalore Tech Talks: GitHub Hacks

Page 90: GitHubHacksBangaloreTechTalks

How to request?• Click on Create new file

Bangalore Tech Talks: GitHub Hacks

Page 91: GitHubHacksBangaloreTechTalks

How to request?

Bangalore Tech Talks: GitHub Hacks

• Enter File Name• Enter Message

Page 92: GitHubHacksBangaloreTechTalks

How to request?• Enter Comments• Click on Propose New File

Bangalore Tech Talks: GitHub Hacks

Page 93: GitHubHacksBangaloreTechTalks

How to request?• Click on Create pull request

Bangalore Tech Talks: GitHub Hacks

Page 94: GitHubHacksBangaloreTechTalks

How to requested?• Enter Comments & Click on create pull request• Done

Bangalore Tech Talks: GitHub Hacks

Page 95: GitHubHacksBangaloreTechTalks

How to Share?• Sign in to your GitHub Account• Search “LoveToShare” • Click on djobsheadstart/LoveToShare Repo• As Shown in image

Bangalore Tech Talks: GitHub Hacks

Page 96: GitHubHacksBangaloreTechTalks

How to Share?• Click on Create new file

Bangalore Tech Talks: GitHub Hacks

Page 97: GitHubHacksBangaloreTechTalks

How to Share?• Enter File Name • Enter Your Message

Bangalore Tech Talks: GitHub Hacks

Page 98: GitHubHacksBangaloreTechTalks

How to Share?• Enter Comments• Click on Propose New File

Bangalore Tech Talks: GitHub Hacks

Page 99: GitHubHacksBangaloreTechTalks

How to Share?• Click on Create pull request

Bangalore Tech Talks: GitHub Hacks

Page 100: GitHubHacksBangaloreTechTalks

How to Share?• Enter Comments & Click on create pull request• Done

Bangalore Tech Talks: GitHub Hacks

Page 101: GitHubHacksBangaloreTechTalks

Thank you! Contact Me: [email protected]

• Register for the GitHub Developer Program• https://github.com/developer/register

Bangalore Tech Talks: GitHub Hacks