github basics
Post on 06-May-2015
6.836 Views
Preview:
DESCRIPTION
TRANSCRIPT
GIT & GITHUB BASICSGameCraft Training Radoslav Georgiev (@Rado_G)
DISCLAIMERI’m not a Git expert or pro
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
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 благинки
No Source Control System =
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
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/
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 git@github.comsome output .. (yes/no)$ yesHi username! You’ve successfully authenticated, but Github does not provide shell access.
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@email.com”
$ git config –global github.user username$ git config –global github.token the_token
DEMO TIME1) Create a Github account
2) Set up with Windows
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
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
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
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
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
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
How it works? Staging area.
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 git@github.com:UserName/ProjectName.git
$ git remote add [name] [url]
$ git remote -v
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]
Recap ! Creating a repo• Create a repo
• Add an remote
• Check if directory is a git repo
$ git init
$ git remote add origin git@github.com:UserName/ProjectName.git
$ ls –laSearch for .git folder
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!
DEMO1) Create yourself a repo (from Github)
2) Add and Commit few files
3) Push them !
4) Repeat 2) and 3) few times
TAKE A BREAK.We all deserve it
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
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!’
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>
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 git@github.com:UserName/ProjectName.git
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]
top related