Gitting into Version Control
An Introduction to Git
Charelle Collett
charcol@redhat.com
@charcol0x89
Stop me if there's anything you don't understand!
Why use version control?

Why use version control?
Keeps a change history of every file
Branches let you, or several people, work on things concurrently
Auditing - where features were introduced, who worked on what
Not a replacement for backups!
Why Git?
Used by popular code hosting services like Gitlab, Github & Bitbucket
Creates a full copy of the whole repository (unlike SVN)
Open source
Powerful features

Remote repository
Local copy
Local copy
Local copy
Server
Collaborator
Collaborator
Collaborator
"Don't try use git's features - that's how you break things"
You should use git's features
GITTING Started
Install git:
apt-get install git
dnf install git
yum install git
Xcode Command Line Tools
Github for Windows:

GITTING Started
Initialise the repository:
Clone an existing repository:
# With --bare it doesn't create a working directory:
# A good idea for shared repositories
$ git init --bare <directory>
$ git clone <URL>

GITTING Started
$ git config --global user.name "Charelle Collett"
$ git config --global user.email "charcol@redhat.com"
$ git config --global --edit
# Remove --global to change settings for a single project
Edit the config:
COMMITING
$ git status
See what changes will be applied:
$ git add <filename>
Add files to commit:
$ git commit -m "message"
Commit your changes:
$ git log
See the history:
Branching
master:
new feature:
experiment based on new feature:
Branching
$ git checkout -b <name-of-branch>
Create a new branch:
This is shorthand for:
Move to a different branch:
$ git checkout <name-of-branch>
$ git branch <name-of-branch>
$ git checkout <name-of-branch>
Pushing / PUlling
$ git push
Remote repository
Local copy
Push your local changes to the remote repository:
$ git pull
Pull new changes from the remote repository to your local copy:
Server
Collaborator
REMOTES
$ git push <remote> <branch>
Push to a specific branch:
Show connections to other repositories:
$ git remote -v
$ git pull <remote>
Pull from a certain remote:
$ git remote add <name> <url>
Add a remote:
$ git remote rm <name>
Remove a remote:
# Only push to a
# bare repository!
GIT Config
.git/config
$ git config --edit
[branch "new-feature"]
remote = origin
merge = refs/heads/new-feature
More terms


Upstream: original source of the code
Fork: a copy of the code
Merge request / pull request: avenue to submit changes
Other useful things...
* cherry-pick
Take a commit and apply it to another branch
* rebase
Change the point where your changes are based
* stash
Save your changes locally (without committing) so you can switch branches
* squash
Combine several commits into one
* patch
Export changes as a patch that can be applied later
* .gitignore
List of files that git should ignore
* diff
See differences between commits
* blame
See who was responsible for changes
More Info
Git documentation:
https://git-scm.com/book/en/v1/Getting-Started
Atlassian's git tutorial:
https://www.atlassian.com/git/tutorials
Github / Code school interactive tutorial:
https://try.github.io/levels/1/challenges/1
Codecademy interactive tutorial:
https://www.codecademy.com/learn/learn-git
Thank you!
Questions?
Charelle Collett
charcol@redhat.com
http://redhat.slides.com/charellecollett/deck-1?token=E29yEW2p
@charcol0x89
Gitting into Version Control
By Charelle Collett