&
Workflows
What is Git?
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
Why?
"I'm an egotistical bastard, and I name all my projects after myself. First 'Linux', now 'git'."
Who Had This To Say:
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
More Fun Facts:
What Git Really Is.....
...a DVCS or Distributed Version Control System
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:
What is GitHub?
GitHub is simply a public website and social network exposing Git remote servers
GitHub hosts some of the worlds most widely used code repositories from some of the most well known software developers in the world
GitHub is a great way to learn, contribute, share and grow.
GitHub
Create Account
SSH Key Auth
Check if you have an existing SSH Certificate
OR...
SSH Key Generation
If you DON'T have an SSH key:
#Create a new RSA encrypted SSH certificate
$ ssh-keygen -t rsa -b 4096
Add SSH Public Key
We now have to upload our SSH public key to Github
Add SSH Public Key
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
Installing Git
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:
Configure Git
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 Basics - Syncing
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 Basics - Making Changes
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
Let's Practice!
- Create a folder to keep your repositories on your Desktop or other location you prefer
# Create a new folder for our demos
$ mkdir ~/Desktop/github-demos
$ cd ~/Desktop/github-demos
Exercise 1.a
Create a Local Repo
# 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."
Exercise 1.b
Create Remote Repo
- Go to GitHub
- Create a New Repository
- Copy the Git Remote URL
#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
NOW CHECK GITHUB!!
Yeeessss
Exercise 2.a
Clone an Existing Repo
# 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 repository on GitHub
- Add a README.md and .gitignore when creating repository on GitHub
Exercise 2.b
Add & Push Changes
# 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
NOW CHECK GITHUB!!
Yeeessss
Working with Branches
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
Git Branching
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
What if I'm working on the wrong branch?
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
Git Flow
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
Adding Contributors
GitHub repo -> Settings -> Collaborators
Adding collaborators to your repository gives others the ability to work on your project
Pull Requests
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
Submitting a Pull Request
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
Merge conflicts will happen so don't.....
.....FREAK OUT!!!
Merge Rule #1
Great tools don't replace the need to communicate with your team. When conflicts happen, find out why.
Merge Rule #2
See Merge Rule #1
.gitignore
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:
GitHub Security
Don't EVER EVER EVER commit secure keys or passwords to your repo.
Security Rule #1
You know what I'm sayin....
Security Rule #2
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
Git Help
#Run this command to read more about Git
$ man gittutorial
Git Kraken
Adding SSH Keys To GitHub
Git Desktop Tutorial
GitHub & Git Workflows
By Jason Sewell
GitHub & Git Workflows
- 2,622