28
GIT & GITHUB BASICS GameCraft Training Radoslav Georgiev (@Rado_G)

Github basics

Embed Size (px)

DESCRIPTION

A company training for the ba

Citation preview

Page 1: Github basics

GIT & GITHUB BASICSGameCraft Training Radoslav Georgiev (@Rado_G)

Page 2: Github basics

DISCLAIMERI’m not a Git expert or pro

Page 3: Github basics

Agenda• Why use Source 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

Page 4: Github basics

Why use Source Control Systems ?

What is ?

• SCS are a tool that helps keeping versions of the code

• SCS allow multiple developers to work on the same code with minimum amount of collisions

Why use ?

• Keeps the developing process simple

• All files are hosted (Github)

• No nose bleed!• Tons of благинки

Page 5: Github basics

No Source Control System =

Page 6: Github basics

Agenda• Why use Source 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

Page 7: Github basics

How to setup Git 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/

Page 8: Github basics

How to setup Git 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 :

• gg, wp

$ ssh –T [email protected] output .. (yes/no)$ yesHi username! You’ve successfully authenticated, but Github does not provide shell access.

Page 9: Github basics

And some configuration ^_^• Name & Email – Github tracks them

• Github API token• On the GitHub site Click “Account Settings” > Click “Account

Admin.”

$ git config –global user.name “Firstname Lastname”$ git config –global user.email “[email protected]

$ git config –global github.user username$ git config –global github.token the_token

Page 10: Github basics

DEMO TIME1) Create a Github account

2) Set up with Windows

Page 11: Github basics

Agenda• Why use Source 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

Page 12: Github basics

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

$ commandOutput of the command

Page 13: Github basics

Agenda• Why use Source 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

Page 14: Github basics

Lets create a repo !• Click on the new repository button in Github• Start the shell (Git Bash)• Execute the super-complex command :

• Great, now we have repo. Lets create a file, shall we ?

$ git initInitialized empty Git repository in c:/code/TestingGithub/.git/

$ touch omgrofl.txt$ notepad omgrofl.txt (and add text) or $ echo “rofllol” > omgrofl.txt$ cat omgrofl.txt cat prints to the outputrofllol

Page 15: Github basics

Lets create a repo ! (cont’d)• Okay, lets add it !

• And commit it

• And for the sake of learning, lets edit it again

$ git add omgrofl.txt

$ git commit –m ‘This is a commit message’Some gitorish output

$ echo “roflcopter” >> omgrofl.txt$ cat omgrofl.txtrofllolroflcopter

Page 16: Github basics

Lets create a repo ! (cont’d)• And now, lets see :

• Outputs :

• Almost there

$ git status

# 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

$ git add omgrofl.txt$ git status

Page 17: Github basics

How it works? Staging area.

Page 18: Github basics

What about Github ? Remotes ?• Okay, you suck, there’s nothing @ Github• Damn. Enter magic!

• Git commits locally, pushes remotely !!!!!!!• Add the remote when the repo is created (git init,

remember ? )

• Want to see the remotes ?

$ git remote add origin [email protected]:UserName/ProjectName.git

$ git remote add [name] [url]

$ git remote -v

Page 19: Github basics

What about Github ? Push it up, baby!

• Okay, we have committed and added a remote to Github. It’s time to push

• Open up the repo in Github and enjoy ^_^• The push command explained :

• Branches are black magic for later • There’s a big chance that the branch you are pushing to

will be named “master”

$ git push origin masterEnter passphrase !

$ git push [remote_name] [branch]

Page 20: Github basics

Recap ! Creating a repo• Create a repo

• Add an remote

• Check if directory is a git repo

$ git init

$ git remote add origin [email protected]:UserName/ProjectName.git

$ ls –laSearch for .git folder

Page 21: Github basics

Recap ! The workflow.• Edit files and check the status

• Add them to the staging area

• Commit the changes

• Push them to Github

• Celebrate !

$ git add file1.php file2.php file3.php

$ git commit –m ‘Commit message that explains the changes’

$ git status

$ git push origin masterEnter passphrase!

Page 22: Github basics

DEMO1) Create yourself a repo (from Github)

2) Add and Commit few files

3) Push them !

4) Repeat 2) and 3) few times

Page 23: Github basics

TAKE A BREAK.We all deserve it

Page 24: Github basics

Agenda• Why use Source 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

Page 25: Github basics

Don’t push your passwords• Use .gitignore

• Something missing ?

$ touch .gitignore$ echo “db_config.php” >> .gitignore$ git add .gitignore$ git push origin masterEnter passphrase!

$ git commit –m ‘You are not seeing my passwords!’

Page 26: Github basics

Made a mistake ? No worries• Unstage something – git reset

• Revert a commit ? Reset hard!

$ git add index.php$ git statusSays it’s staged. I don’t want to ! I changed my mind.$ git reset HEAD – index.php$ git statusNow I’m happy ^_^

$ git reset –hard HEAD~1OR$ git reset –hard <commit_id>

Page 27: Github basics

Fork time.• If you want to get a repo – fork is the way.• Fork on github and then

• 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/

$ git clone [email protected]:UserName/ProjectName.git

Page 28: Github basics

Shared repos• If you 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.

• This will pull the latest changes

$ git pull [remote_name]