Pages

Monday, January 4, 2016

Github / Git

Create new GitHub repository


// *********** github SSH public key
ssh-keygen -C "david.pasek@gmail.com"
Add pub key (.ssh/id_rsa/id_rsa.pub) to GitHub ... Settings > SSH and GPG keys > New SSH key

// *********** 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
 
// *********** You must create the repository on GitHub manually
Type git remote add origin git@github.com:davidpasek/[REPOSITORY-NAME].git
Type git push push --set-upstream origin main

Clone existing GitHub repository

// *********** Clone existing github repository with username and token
git clone https://github.com/davidpasek/math4kids
 
// *********** Clone existing github repository with SSH key
git clone git@github.com:davidpasek/uw.cz-gitops.git

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