Pages

Monday, January 4, 2016

Github / Git

// *********** github config
git config --global user.name "davidpasek"
git config --global user.email "david.pasek@gmail.com"

// *********** Create new git repository from directory
Create a directory to contain the project.
Go into the new directory.
Type git init
Write some code.
Type git add -A to add all the files from current directory.
Type git commit

// *********** Clone existing github repository
git clone https://github.com/davidpasek/math4kids

// *********** Add file to github

git status
git add file.html
git commit -m "Commit comment"

// push back to github
git push

// pull out from github
git pull

// *********** Add all files in local directory to github
git add -A
git commit -m "Initial add of files into the repository"
git push

// *********** Working with github - commit changes
git status
git pull
... working with files
git commit -a
git push
git status

GLOBAL CONFIG
git config --global user.name "David Pasek"
git config --global user.email david.pasek@gmail.com

Save credentials
$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>

[several days later]
$ git push http://example.com/repo.git
[your credentials are used automatically]

Q&A
Q: What is the difference between git clone and git checkout?
A: 
The man page for checkout: http://git-scm.com/docs/git-checkout
The man page for clone: http://git-scm.com/docs/git-clone
To sum it up, clone is for fetching repositories you don't have, checkout is for switching between branches in a repository you already have.

Links:
Visual GIT reference - http://marklodato.github.io/visual-git-guide/index-en.html
GIT Simple Guide - http://rogerdudler.github.io/git-guide/
How To Use Git Effectively -  https://www.digitalocean.com/community/tutorials/how-to-use-git-effectively

No comments:

Post a Comment