git overview
TRANSCRIPT
GIT Introduction - youEngineering
GIT key features
Own local repository
Branching is easy
Its fast
Working without connection to the central
repository
GIT Configuration
Global git config —> .gitconfig
Project git config —> .git
Ignore files —> .gitignore
https://www.gitignore.io/ —> templates for
.gitignore
GIT Areas
LOCAL
REPO
STAS
H
WORKSPA
CESTAGING UPSTREAM
REPO
YOUR LOCAL
COMMITS
YOUR FILES
READY TO COMMIT
LOCALLY
YOUR LOCAL
CHANGES
YOUR
TEMPORARY
BACKUP OF
CHANGES
GIT Tools
GITK
UI showing your
local repository
GIT GUI
UI showing your
index
unstaged
changes
staged
changes
content of
selected file
git gui
history
changes in
files
file list of
selected
commit
gitk
GIT Mergetool (for command line
user)
install p4merge
edit mergetool in .gitconfig
git mergetool
Area - Stash
Place to save modifications if you wanna work on
something else
stash list show all stashes
stash pop pop last stash
stash apply [stash] apply stash from list
stash save [message] save stash with message
stash clear clear all stashes and lose your modifications
Area - Workspace
Local checkout and working directory
git gui gui to watch your staging area
git status show status of your workspace
git diff show your local changes
git add . add all files to staging
git commit -a -m [message] add to staging and commit to
local repo in one command
Area - Index/Staging
Staging area - files ready to get committed to local
repo
git status show status of your index
git commit -m commit staged files
git rm —chached [file] remove added file from index
git reset HEAD staged files are back to unstaged
git checkout [file] unstaged file will lose all changes
Area - Local repo
Local repository
gitk show guy to track local commits
git push push local commits to repo
git reset HEAD^1 reset last commit to unstaged area
git reset —soft HEAD^1 reset last commit to staged area
git reset —hard HEAD^1 removes last commit, changes lost
git revert HEAD^1 creates a revert commit for the last local committed
changes
git revert [commitid] revert a specific commit - commit id can be tracked with
git log
Area - Upstream repository
the actual repository on the server
git push push local commits to the upstream
git pull pull changes from upstream to the local
repository. If there are local changes you need to
stash them first or commit it locally
Head, Master, Origin, wtf?
git branch -a shows local and remote branches
*master
remotes/origin/HEAD -> origin/master
remotes/origin/master
origin = remote repository name (default)
*master = local branch
remotes/origin/master = “remote” branch, last time checked!
head = pointer to the current commit, normally last commit in current
branch
pull, fetch, merge, holy…
git pull = git fetch + git merge
git fetch = updates remote tracking branches in local
repository, you can do it always without losing your
working directory changes
after a fetch you can do: git diff master origin/master
to see what changed
git pull will then merge all changes into your local
directory
fast forward merge?
default is always “fast forward”
if git detects that the remote branch didn't change
during your work on your local branch, it will just
point to the latest commit of your branch
if the remote branch changed, git will create a
merge commit
in the end: the history is different
GIT Flows
Normal flow
git add . add current changes in the current directory
git commit -m “Test commit message” Commit to local repository
git push Commit to upstream repository
Amend commit
Idea: include new commit in already local committed changes
git commit —amend -m [message]
New commit will get “merged” into last local commit with the new commit
message
GIT Flows
Normal update
git pull (= git fetch + git merge) get changes from
remote repo into local branch
git fetch only fetch changes to remote tracking
branches
git diff local_branch origin/master see fetched
changes
git merge merge fetched changes into local branch
GIT Flows
Feature branches
git checkout -b new_feature_branch master creates feature branch
based on branch master
there is no difference between a master or another branch in the
repository
git push -u origin new_feature_branch push feature branch into the
upstream origin
git checkout master feature is finished, back to master branch
git merge new_feature_branch merge feature branch into master,
don't forget to check that you pulled everything from the master branch
so its definitely up2date
GIT Flows
Merge commits between branches
git checkout some_branch change your current branch to
some_branch
we did some changes and committed it to the some_branch, now
we want to merge it into our some_other_branch
git log we look up the id of our last commit
git checkout some_other_branch change to our other branch
git cherry-pick ef4876c753c4e669fd2600d9c5b7447de729f3b3
cherry picks the commit and commit it to our current branch locally