Git & Github
Speakers
- Mohit Kumar Bajoria
- Iresh Mishra
Quick Poll
- What is source code?
- What is open source?
- Who has used git?
- Who has used github?
Open Source?
- Source code is available (to Mess) with, modify it and can be distributed generally.
- It can be free or not.
You told me source code is available to play with but where I will get the source code.
Wait a second!
Github is one of the place on Internet where you can get source code of various famous open source projects like VLC, AngularJS, ReactJS etc.
Why do I need that?
• to undo errors / roll back to earlier versions of code
• to share a codebase between any no. of developers without creating conflicts
• to deploy changes from development to staging or production environments
What the heck is Git?
Git is a version control system(VCS) which is a tool to manage the history of our Source Code.
What is Version control system?
It allows you to:-
- Revert Files to Previous State
- Revert Entire Projects to Previous State
- Compare Changes Over Time
- See who modified what...& much more...
Time for a Demo
Need 5 volunteers
Real Life
example?
Yes.
- It is like the parent of your code. Just like your parents know about the changes in your life. Git knows the changes happened in the life of code. Your life can not be reverted but git can go the past if something wrong happens.
- It takes a snapshot of the code in the history of Project. So if things goes wrong, you can revert back to the most recent working version.
Github?
Github is a place to store your git projects online.
It is a social network for Developers.
Github allows you to work in a Team
Github allows to
- Get the source code of various open source projects
- Contribute to these projects.
- Make your project open source.
- Work with team to create awesome stuff.
- Manage different versions of your project.
- Create an online resume to showcase the projects you own and contributed to.
Review
- What is Open Source?
- Git
- Github
Getting your hands dirty..
Sign Up on Github
Setting up Git
$ git config --global user.name "YOUR NAME"
- Tell Git your E-mail
$ git config --global user.email "YOUR EMAIL ADDRESS"
Don't worry. The above set up is to be done only once.
Create a Repository
Repository?
- Github Repository is a fancy name for folder on Github
- This folder contains all your project files.
Repository is created
Create a local copy of Github repository
$ git clone https://github.com/mbj36/Github-Workshop.git
It will create a folder in your computer with the same files on github.
Review
- Setting up git on your computer
- What is a Repository?
- How to clone a Github Repository
What's next?
Start working on your project..
Create a new file in your project like sfd.txt
Software Freedom Day is everywhere!
SFD is a yearly celebration for Software Freedom!
Every year there are thousands teams organizing
Software Freedom Day in different
countries and cities.
sfd.txt
Great! you have created a new file locally. Now its time to send this file on Github so others can see it.
Now Git will come into picture
Git will version control this file named sfd.txt to record the changes happening with file over time.
Git status
Run git status inside project folder.
Git add
Run git add for tracking new files.
hp lapi@hp MINGW64 ~/Desktop/Github-Workshop (master)
$ git add .
Git status
Check the status again.
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: sfd.txt
Git commit
It is a snapshot of your code.
hp lapi@hp MINGW64 ~/Desktop/Github-Workshop (master)
$ git commit -m"Created Text File"
[master 1977c06] Created Text File
1 file changed, 5 insertions(+)
create mode 100644 sfd.txt
-m = commit message
Git status
Check the status again.
hp lapi@hp MINGW64 ~/Desktop/Github-Workshop (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
We have created sfd.txt file locally but how to send it to Github
Git push
Git push send all commits to github.
hp lapi@hp MINGW64 ~/Desktop/Github-Workshop (master)
$ git push origin master
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 402 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/mbj36/Github-Workshop.git
218a38a..1977c06 master -> master
Now our github looks like
Great you have made your first Open Source contribution.
Review
- Git status
- Git add
- Git commit
- Git push
Git Mantra
Add
Commit
Push
Check the status often.
Learn More
these are the basics
Find a project that interests you and fork it
Fork?
It is creating a copy of project to your account.
Original Project
Forked Project
This is your copy of the project. Modify it as you like and follow the Git Mantra.
Remember the Git Mantra..
You have made some awesome changes in the project
What's next?
Open a Pull Request
With Pull request you are asking the maintainer of project to add your changes to the main project.
Maintainer will check the changes and merge it if its correct
Awesome! You are now an Open Source Contributor.
Review
- Fork a project
- Follow Git Mantra
- Open a Pull Request
Git beyond basics
- git rebase
- git merge
- git stash
- git reset
- solve git conflicts
Learning Resources
Any Questions?
Thank You
Copy of SFD-2016 Github Workshop
By slides4fun
Copy of SFD-2016 Github Workshop
Slides for Github workshop in Software Freedom Day 2016.
- 1,616