04-07-2017
Begginer
Version Control
Git? What and why
Getting Started
Setting up a Repository
Saving Changes
Inspecting a Repository
Undoing Changes
Rewriting History
Collaborating
Syncing
Pull (Merge) Requests
Using Branches
GIT Workflow
Practical Info
Basic Conventions
Source Tree
Avoid Disasters
FAQ
Beginner
Beginner
--local, --global, --system git config --local user.email <email>
git config --global user.name <name>
git config --global alias.<alias> <command>
git config --system core.editor "<editor> -w"
Getting Started
git config
git config --local user.email "jgmarques@kpmg.com"
git config --global user.name "jgmarques"
git config --global alias.ci commit
git config --global alias.amend git ci --amend
git config --system core.editor "atom -w"
Getting Started
git config
Getting Started
git init
Getting Started
git clone <repo url>
Getting Started
git add
Getting Started
git commit
Getting Started
git stash
Getting Started
.gitignore
Getting Started
git status
Getting Started
git log
git log -n <limit>
git log --oneline
git log --author="<pattern>"
git log --grep="<pattern>"
git log <since>..<until>
Getting Started
git checkout
git checkout <branch>
git checkout <commit>
git checkout <commit> <file>
Getting Started
git revert
Getting Started
git reset
Getting Started
git clean
Getting Started
Getting Started
git commit --amend
Getting Started
git rebase <base>
Getting Started
git rebase -i <base>
Collaborating
git remote
Collaborating
git fetch
Collaborating
git pull
Collaborating
git push
Collaborating
Collaborating
Collaborating
git branch
git branch
git branch <branch>
git branch -d <branch>
git branch -D <branch>
git branch -m <branch>
Collaborating
git checkout
git checkout <existing branch>
git checkout -b <new branch>
Collaborating
git merge
Collaborating
Practical Info
Practical Info
Practical Info
Practical Info
Practical Info
Q: How to discard local file modifications?
A: git checkout -- <filename>
Practical Info
Q: How to undo the last 2 commits?
A1: git reset HEAD~2 (undoes and keeps changes)
A2: git reset --hard HEAD ~2 (undoes and discards changes)
Q: How to unstage a file?
A: git reset <filename>
Q: How to edit a commit message?
A: git commit --amend -m "<new message>"
Practical Info
Q: How to revert a commit that has already been pushed to the server?
A1: git revert <commit id>
A2: git revert <commit id 1>..<commit id 2> (reverts a range)
Q: How to undo the last commit only locally?
A: git revert -n HEAD
Q: How do I find the commit that broke the code?
A: git bisect
Practical Info
Q: How to revert a commit that has already been pushed to the server?
A1: git revert <commit id>
A2: git revert <commit id 1>..<commit id 2> (reverts a range)
Q: How do I know what my last actions were, accross all branches?
A: git reflog
Q: I just committed something to master that should have been in a new branch. Now what?
# First, create the branch that you should have been working on
git branch <branch>
# Then, reset master to the previous state, removing the last commit
git reset HEAD~ --hard
# Finally, switch to the new branch, where your commit will be
git checkout <branch>
Practical Info
Q: I just committed something to the wrong branch. Now what?
# First, undo the last commit, keeping the changes
git reset HEAD~ --soft
git stash
# Change to the correct branch
git checkout <other branch>
# Apply the changes to this branch
git stash pop
git add <whatever you want to stage>
got commit -m "<commit message>
Practical Info
Q: I have no idea what's going on with my repo. Nothing works. Now what?
A: Delete the repository, and clone it again :)
Practical Info