Upload
abhishek-kumar-gupta
View
159
Download
0
Embed Size (px)
Citation preview
Abhishek Gupta@abhiguptame
Bangalore Tech Talks: GitHub Hacks
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
Bangalore Tech Talks: GitHub Hacks
One Request!• Stop me, If you want me repeat some concepts.
Agenda • Version Control System • Git & GitHub Basics • GitHub beyond Master, Branch & Pull Requests• Interesting Facts • Important Links
Bangalore Tech Talks: GitHub Hacks
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.
Version Control System• Without• Local• Centralized• Distributed
Bangalore Tech Talks: GitHub Hacks
What ?
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
Local Version Control Systems• Just a local Database• Systems: • Revision Control System
Bangalore Tech Talks: GitHub Hacks
What If?
Bangalore Tech Talks: GitHub Hacks
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
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
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
Distributed Version Control Systems
Bangalore Tech Talks: GitHub Hacks
• Distributed: each client has fully mirror of the repository• Systems:• Git • Mercurial, Bazaar
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
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
What is
Bangalore Tech Talks: GitHub Hacks
&
• 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
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.
Flow• Installing • Configuring Git with Github• Working locally with Github• Working remotely with Github
Bangalore Tech Talks: GitHub Hacks
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
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
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
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
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
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
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
Bangalore Tech Talks: GitHub Hacks
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
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
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
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
Bangalore Tech Talks: GitHub Hacks
Before Cloning
After Cloning
Readme File
The Three States
Bangalore Tech Talks: GitHub HacksModified/UntrackedStaged Committed
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
Removing
Bangalore Tech Talks: GitHub Hacks
git rm file_name/ Stages a removed file
git rm -r folder_name/
Stages a removed folder
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
Committing and Pushing• If you want to commit changes to your local repository, you use the following command:
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
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
Bangalore Tech Talks: GitHub Hacks
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
Merges• Merge on the current branch changes made on another branch• $ git merge branch_name
Bangalore Tech Talks: GitHub Hacks
.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
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
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
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Take a break.•We all deserve it
Bangalore Tech Talks: GitHub Hacks
your career partnerEvent Host Partner
GitHub beyond Master, Branch & Pull Requests
Bangalore Tech Talks: GitHub Hacks
GitHub++• GitHub For Desktop• GitHub Pages for Website Hosting• GitHub Pages for Project Website
Bangalore Tech Talks: GitHub Hacks
GitHub For Desktop
Bangalore Tech Talks: GitHub Hacks
https://desktop.github.com/
Bangalore Tech Talks: GitHub Hacks
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
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Using a Custom Domain• Create a new file name CNAME• Yourdomain.com [www.abhinotes.com]
Bangalore Tech Talks: GitHub Hacks
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
Bangalore Tech Talks: GitHub Hacks
GitHub Pages for Project Website
• https://pages.github.com/
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
GitHub++• Git Resume• Visit the following repo and Star this project
Bangalore Tech Talks: GitHub Hacks
Git Resume
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
GitHub++• GitHub For Students (.edu Email Id)
https://education.github.com/pack
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
Bangalore Tech Talks: GitHub Hacks
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
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
Interesting Facts:
Bangalore Tech Talks: GitHub Hacks
ProGit Book• https://github.com/opendream/progit
Bangalore Tech Talks: GitHub Hacks
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
Questions
•Any Questions?
Thank you! @abhiguptame
Bangalore Tech Talks: GitHub Hacks
What Next?
djobsHeadStart
Bangalore Tech Talks: GitHub Hacks
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
djobsheadstart• https://www.github.com/djobsheadstart• https://github.com/djobsheadstart/LoveToShare• https://github.com/djobsheadstart/RequestToLearn
Bangalore Tech Talks: GitHub Hacks
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
How to request?• Click on Create new file
Bangalore Tech Talks: GitHub Hacks
How to request?
Bangalore Tech Talks: GitHub Hacks
• Enter File Name• Enter Message
How to request?• Enter Comments• Click on Propose New File
Bangalore Tech Talks: GitHub Hacks
How to request?• Click on Create pull request
Bangalore Tech Talks: GitHub Hacks
How to requested?• Enter Comments & Click on create pull request• Done
Bangalore Tech Talks: GitHub Hacks
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
How to Share?• Click on Create new file
Bangalore Tech Talks: GitHub Hacks
How to Share?• Enter File Name • Enter Your Message
Bangalore Tech Talks: GitHub Hacks
How to Share?• Enter Comments• Click on Propose New File
Bangalore Tech Talks: GitHub Hacks
How to Share?• Click on Create pull request
Bangalore Tech Talks: GitHub Hacks
How to Share?• Enter Comments & Click on create pull request• Done
Bangalore Tech Talks: GitHub Hacks
Thank you! Contact Me: [email protected]
• Register for the GitHub Developer Program• https://github.com/developer/register
Bangalore Tech Talks: GitHub Hacks