Beruflich Dokumente
Kultur Dokumente
Introduction
● I’m not a git master :p
Introduction
● I’m not a git master :p
● We’ll use Eclipse built-in Git Repository
Introduction
● I’m not a git master :p
● We’ll use Eclipse built-in Git Repository
● We’ll try to cover up some of the cli
commands
Introduction
● I’m not a git master :p
● We’ll use Eclipse built-in Git Repository
● We’ll try to cover up some of the cli
commands
● We’ll use BitBucket but of course in reality,
we’re going to set up our test server.
What is GIT?
- is a distributed version control system rather than centralized version control system (SVN, CVS, etc.)
- it means that when you ‘clone’ (checkout), you’re actually copying the repository to your local. Having a local
repository(full backup) has many advantages. File history, for example, is then looked up to your local machine rather
than remotely.
- Furthermore, when server dies(everything destroyed!). Any updated client that has the full backup can copied back up
to the server to restore it.
Why GIT over SVN?
● Speed. Git is very fast when it comes to committing and updating your
working copy.
● Work Locally. You can commit, create branch, create tag, etc. locally in
GIT. This feature is really useful when you are creating a production
feature and want to pause at the moment and maybe fix a critical bug.
● Mature Branching. switching branch in GIT is very fast. SVN is way behind
it. Branching allows us to keep a copy of the repo and make changes to
that copy. You may later ‘merge’ changes that branch to ‘master’ branch or
other branch.
● Pro Agile. But that doesn’t mean that SVN is anti-agile. It’s just GIT has
lots of ‘speed of light’ kind of features that’ll make development faster. One
of them is again, branching.
Git States
● Modified. File was changed.
● Staged. File was modified and marked as ready to commit.
● Committed. File changes were committed to your local repo. See it in
history
● Tracked. Files that are in repository.Either modified,staged, or committed.
● Untracked. Files that are ‘newly’ created and are not yet in repository
Creating a repository (CLI)
1. Create BitBucket repository.
2. Create a local directory and change directory to it.
3. git init. This will create .git which contains all necessary information of your repo.
4. git remote add origin <http://url/blah/blah/blah.git>. This will set remote information of newly initialized repo.
5. git add README.txt. This will add the README.txt to ‘index’ or basically means stage the modified/new file.
Don’t get confused with ‘svn add’ which adds NEW file. ‘git add’ will set file(s)’s state, whether new file or existing
file to ‘Staged’.
6. git commit -m ‘message here’. This will commit the staged files to local repo.
7. gitk. [Optional] Shows a gui to check history
8. git push -u origin master. Push changes to remote server. (-u means set the upstream to ‘origin master’. So that
on next pull you may ‘git pull’ instead of ‘git pull origin master’.)
Creating a repository (Eclipse)
1. Create BitBucket repository.
2. ‘Create Git Repository’ on Git repository perspective.
3. Type in name and destination directory
Creating a repository (Eclipse)
4. Right click at ‘Remotes’ and choose ‘Create Remote...’
5. Type in ‘origin’ in ‘Remote name’. Let configure push selected as we will do a push later.
6. Click ‘Change’ in Configure Push dialog
7. Paste in the URI. Notice the dialog is same as when cloning.
Creating a repository (Eclipse)
8. Click save
9. Create README.txt file on destination directory
10. Go back to Eclipse and hit ‘Refresh’. You should see something like
Creating a repository (Eclipse)
11. Right click README.txt and ‘Add to index’
12. On lower part of Eclipse fill out the following and finally press ‘Commit and Push’!!!
GIT States Demo
go back to slide 8
git status - check repo status. what branch? what file changes?
git commit - commit local
git add <file> - stage/index the file.
git rm --cached <file> - unstage/unindex the file. (Important: --cached must be present to retain the file)
gitk - quick gui commit log
git log - cli type commit log
git diff - show differences
Ignore Files
create .gitignore file and add pattern per line
/target
/.classpath
/.settings
/.project
/bin
Eclipse way:
Right click delete…
Windows way:
delete file
git add <file> or “Add to index” in eclipse
“Compare with Version in Ancestor” -> opens compare window and compares the file from previous version
“Compare with Workspace” -> opens compare window and compares the file from workspace (modified file)
Pushing to remote
● Pushing to upstream is very simple just “git push” or “Push to Upstream” in Eclipse.
● In Eclipse, there is a single click “Commit and Push”.
● CLI, “git push” or “git push origin master”. The latter pushes the changes to ‘master’ branch if upstream is not
configured. To configure upstream you do a “git push -u origin master”.
● Remember: You can’t push codes if you’re local repo is not updated. You will see ‘non-fast forward’ dialog.
Pulling (No Local Changes)
1. Do a Fetch
2. Do a Merge
3. Or simply ‘Pull’ (fetch and merge)
Pulling (With Changes)
1. Do a Fetch (origin/master will show the latest commit id)
2. Important modified files must be committed
3. Do a merge (Fast-Forward means that if there is not changes on your machine, GIT will be smart enough to skip
merging and just fast forward to latest commit). Often there will be conflicts, see next slide.
Resolving Conflicts
When you merge origin/master to your local master, there’s a
large possibility that you will encounter conflicting files.
Resolving Conflicts
Right click the file then open “Merge Tool”.
Choose “Use HEAD …”
Resolve using GUI
Click “Save”
You’re not done yet. Go back to Git Staging
area. Add to index. Then “Commit”
Reset File
“Replace with HEAD revision” in Eclipse
e.g.
git reset --hard HEAD~1 (undo previous commit)
git reset --hard ff9283… (reset up to commit id)
e.g.
git reset --soft HEAD~1 (undo previous commit and move changes on that commit to index)
git reset --soft HEAD~2 (undo 2 previous commit and move changes on that commit to index)
Branching
git branch <branch name> - creates branch from HEAD (head is a pointer to your current working area)
Pids loves going back to dec 5 release branch and testing ChartStream :)
Branching
Pushing branches to remote