git n. - a person, especially a man, who is stupid or unpleasant
Git was created by a somewhat unknown but warm hearted software developer by the name of Linus Torvalds
"I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git'."
The name "git" was given by Linus Torvalds when he wrote the very first version. He described the tool as "the stupid content tracker" and the name as (depending on your mood): - random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of "get" may or may not be relevant. - stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang. - "global information tracker": you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room. - "g****mn idiotic truckload of sh*t": when it breaks
Prior version control systems required an available server connection to commit work, among other "design flaws"
Git was a solution to allow developers to work in a distributed manner with a full copy of the repository regardless of connection
Git was built around the concept that: "Branches are cheap and easy"
VERY simply:
Create Account
Check if you have an existing SSH Certificate
OR...
If you DON'T have an SSH key:
#Create a new RSA encrypted SSH certificate
$ ssh-keygen -t rsa -b 4096
We now have to upload our SSH public key to Github
Make sure you copy your PUBLIC key (id_rsa.pub)
#Mac
pbcopy < ~/.ssh/id_rsa.pub
# Windows
clip < ~/.ssh/id_rsa.pub
#Linux
xclip -selection clipboard ~/.ssh/id_rsa.pub
Mac:
Linux:
# Debian/Ubuntu
$ sudo apt-get update
$ sudo apt-get install git-all
# Fedora
$ sudo yum update
$ sudo yum install git-all
#Archlinux
$ pacman -S git
Windows:
Set username and e-mail:
$ git config --global user.name "Jay Won"
$ git config --global user.email jay@won.com
$ git config --global push.default simple
$ git config --list
git clone
Copy an existing remote repository to your machine
git init
Create a new repository on your machine
git pull
Pull new changes from a remote repository to your machine
git push
Push new changes from your machine to a remote repository
git add
Add changed files to the index
git commit
Commit staged(added) files to repository history
git status
Check for status of repository and index state at any time
git log
See commit logs on any branch
# Create a new folder for our demos
$ mkdir ~/Desktop/github-demos
$ cd ~/Desktop/github-demos
# Create a new folder for our first demo
$ mkdir git-init-demo
$ cd git-init-demo
$ git init
$ git status
$ echo "# git-init-demo" >> README.md
$ git add README.md
$ git commit -m "First commit."
#Sync the local repository with the new remote repository
$ git remote add origin git@github.com:jaywon/git-init-demo.git
#Push local changes up to GitHub
$ git push -u origin master
# Create a new folder for our first demo
$ cd ~/Desktop/github-demos
$ git clone git@github.com:jaywon/git-clone-demo.git
$ ls
$ cd git-clone-demo
$ ls
$ git status
# Create a new file and add to repo
$ touch index.js
$ git add index.js
$ git commit -m "Add new file."
$ git push origin master
$ git log
Collaboration with others is one of the MAIN reasons we use version control
Using branches gives us a good way to work independently and merge our changes when ready
Every repository starts with a single branch called master
git checkout
Create or switch to another branch
git merge
Merge changes from another branch into current branch
$ git checkout -b feature/new-feature
$ git checkout feature/existing-feature
$ git checkout development
$ git merge feature/new-feature
git branch
Find out status of current branches
$ git branch -a
git stash
Stash current changes to switch to another branch
git stash list
See stashed changes
git stash apply
Re-add stashed changes to current branch
There are many workflows for working in teams and git flow is just one of them with the following rules:
1. All changes are done on develop or development
2. Single developers work on feature branches to work on their features
3. When new changes are ready to be deployed they are merged to master
GitHub repo -> Settings -> Collaborators
Adding collaborators to your repository gives others the ability to work on your project
One of the most effective things you can do to ensure quality and reduce bugs is have other team members review your code
Using the git flow branching workflow makes handling pull requests a simple and efficient process
1. To submit a pull request push your changes up to your GitHub remote branch
2. Go to GitHub and you should see your branch available to create a pull request.
3. Fill out any additional comments, tag any team members and submit the pull request!!
Merge conflicts will happen so don't.....
.....FREAK OUT!!!
Great tools don't replace the need to communicate with your team. When conflicts happen, find out why.
See Merge Rule #1
Depending on your language you will want to use a .gitignore to keep cruft or automated files and folders out of your repository
See here for a common list of .gitignore files:
Don't EVER EVER EVER commit secure keys or passwords to your repo.
You know what I'm sayin....
Add these files to your .gitignore and document how to set the project up for other team members to add these files to their environments
#Run this command to read more about Git
$ man gittutorial
Git Kraken
Adding SSH Keys To GitHub
Git Desktop Tutorial