Git and GitHub basics provides an overview of source control systems and how to use Git and GitHub. It discusses why to use source control, how to set up Git and GitHub on Windows, basic terminology, how to create repositories and push code to GitHub, ignoring files, reverting commits, forking repositories, and pulling changes in shared repositories. The document includes demonstrations of key commands like init, add, commit, push, status, clone and pull.
Agenda
⢠Why useSource Control System ?
⢠How to setup Git and Github on Windows ?
⢠Terminology
⢠Repositories 1.0 â git {init, add, commit, push, remote}
⢠Repositories 2.0 â .gitignore, git {clone, pull, revert, mv,
rm}
⢠Fork & Pull + Shared Repos
4.
Why use SourceControl Systems ?
What is ? Why use ?
⢠SCS are a tool that helps ⢠Keeps the developing
keeping versions of the process simple
code ⢠All files are hosted
⢠SCS allow multiple (Github)
developers to work on the ⢠No nose bleed!
same code with minimum ⢠Tons of йНагинки
amount of collisions
Agenda
⢠Why useSource Control System ?
⢠How to setup Git and Github on Windows ?
⢠Terminology
⢠Repositories 1.0 â git {init, add, commit, push, remote}
⢠Repositories 2.0 â .gitignore, git {clone, pull, revert, mv,
rm}
⢠Fork & Pull + Shared Repos
7.
How to setupGit and Github on
Windows?
⢠First of all â create a Github Account
⢠And second :
⢠Thereâs a great guide @ the Github site -
http://help.github.com/win-set-up-git/
8.
How to setupGit and Github on
Windows? contâd
⢠Youâll need msysgit (Linux shell)
⢠Youâll have to generate an SSH key-pair
⢠And think of a passphrase ! <- Important
⢠Youâll have to add the SHH keys to your Github account
⢠Then test : $ ssh âT git@github.com
some output .. (yes/no)
$ yes
Hi username! Youâve successfully authenticated, but Github
does not provide shell access.
⢠gg, wp
9.
And some configuration^_^
⢠Name & Email â Github tracks them
$ git config âglobal user.name âFirstname Lastnameâ
$ git config âglobal user.email âemail@email.comâ
⢠Github API token
⢠On the GitHub site Click âAccount Settingsâ > Click âAccount
Admin.â
$ git config âglobal github.user username
$ git config âglobal github.token the_token
Agenda
⢠Why useSource Control System ?
⢠How to setup Git and Github on Windows ?
⢠Terminology
⢠Repositories 1.0 â git {init, add, commit, push, remote}
⢠Repositories 2.0 â .gitignore, git {clone, pull, revert, mv,
rm}
⢠Fork & Pull + Shared Repos
12.
Some basic Terminology
â˘git = the shell command to work with Git
⢠repo = Repository, where the code for a given project is
kept
⢠commit = verb, means push the code to the server (in
Git, commit = (commit + push)
⢠diff = the difference between two versions of a file
⢠SSH = Secure SHell â Network protocol for
communication between machines
⢠RSA = Rivest, Shamir, Adleman â public-key
cryptography algorithm
$ command
Output of the command
13.
Agenda
⢠Why useSource Control System ?
⢠How to setup Git and Github on Windows ?
⢠Terminology
⢠Repositories 1.0 â git {init, add, commit, push,
remote}
⢠Repositories 2.0 â .gitignore, git {clone, pull, revert, mv,
rm}
⢠Fork & Pull + Shared Repos
14.
Lets create arepo !
⢠Click on the new repository button in Github
⢠Start the shell (Git Bash)
⢠Execute the super-complex command :
$ git init
Initialized empty Git repository in c:/code/TestingGithub/.git/
⢠Great, now we have repo. Lets create a file, shall we ?
$ touch omgrofl.txt
$ notepad omgrofl.txt (and add text) or $ echo ârofllolâ > omgrofl.txt
$ cat omgrofl.txt ď cat prints to the output
rofllol
15.
Lets create arepo ! (contâd)
⢠Okay, lets add it !
$ git add omgrofl.txt
⢠And commit it ď
$ git commit âm âThis is a commit messageâ
Some gitorish output
⢠And for the sake of learning, lets edit it again
$ echo âroflcopterâ >> omgrofl.txt
$ cat omgrofl.txt
rofllol
roflcopter
16.
Lets create arepo ! (contâd)
⢠And now, lets see :
$ git status
⢠Outputs :
# On branch master
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: omgrofl.txt
⢠Almost there
$ git add omgrofl.txt
$ git status
What about Github? Remotes ?
⢠Okay, you suck, thereâs nothing @ Github
⢠Damn. Enter magic!
$ git remote add origin git@github.com:UserName/ProjectName.git
⢠Git commits locally, pushes remotely !!!!!!!
⢠Add the remote when the repo is created (git init,
remember ? ď)
$ git remote add [name] [url]
⢠Want to see the remotes ?
$ git remote -v
19.
What about Github? Push it up, baby!
⢠Okay, we have committed and added a remote to Github.
Itâs time to push ď
$ git push origin master
Enter passphrase ! ď
⢠Open up the repo in Github and enjoy ^_^
⢠The push command explained :
$ git push [remote_name] [branch]
⢠Branches are black magic for later ď
⢠Thereâs a big chance that the branch you are pushing to
will be named âmasterâ
20.
Recap ! Creatinga repo
⢠Create a repo
$ git init
⢠Add an remote
$ git remote add origin git@github.com:UserName/ProjectName.git
⢠Check if directory is a git repo
$ ls âla
Search for .git folder
21.
Recap ! Theworkflow.
⢠Edit files and check the status
$ git status
⢠Add them to the staging area
$ git add file1.php file2.php file3.php
⢠Commit the changes
$ git commit âm âCommit message that explains the changesâ
⢠Push them to Github
$ git push origin master
Enter passphrase!
⢠Celebrate ! ď
22.
DEMO
1) Create yourselfa repo (from Github)
2) Add and Commit few files
3) Push them !
4) Repeat 2) and 3) few times
Agenda
⢠Why useSource Control System ?
⢠How to setup Git and Github on Windows ?
⢠Terminology
⢠Repositories 1.0 â git {init, add, commit, push, remote}
⢠Repositories 2.0 â .gitignore, git {clone, pull, revert,
mv, rm}
⢠Fork & Pull + Shared Repos
25.
Donât push yourpasswords
⢠Use .gitignore
$ touch .gitignore
$ echo âdb_config.phpâ >> .gitignore
$ git add .gitignore
$ git push origin master
Enter passphrase!
⢠Something missing ?
$ git commit âm âYou are not seeing my passwords!â
26.
Made a mistake? No worries
⢠Unstage something â git reset
$ git add index.php
$ git status
Says itâs staged. I donât want to ! I changed my mind.
$ git reset HEAD â index.php
$ git status
Now Iâm happy ^_^
⢠Revert a commit ? Reset hard!
$ git reset âhard HEAD~1
OR
$ git reset âhard <commit_id>
27.
Fork time.
⢠Ifyou want to get a repo â fork is the way.
⢠Fork on github and then
$ git clone git@github.com:UserName/ProjectName.git
⢠This inits a new Git repository!
⢠You can do everything with the code now â this is a
separate repository.
⢠More @ http://help.github.com/fork-a-repo/
28.
Shared repos
⢠Ifyou are added as a collaborator @ some repo â you
can do everything (clone, add, commit, push) without
restrictions.
⢠Shared repos mean more developers. More Developers =
more changes.
$ git pull [remote_name]
⢠This will pull the latest changes ď