A Quick Start - Version Control with Git


Published on

A quick start guide for the developers, who are used to work with other version control systems, but consider switching to Git

Published in: Internet, Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

A Quick Start - Version Control with Git

  1. 1. Dmitry Sheiko @sheiko A Quick Start – Version Control with Git
  2. 2. What is Git?
  3. 3. Why do people love Git?
  4. 4. How is Git distributed?
  5. 5. What does Git give us? rep o rep o rep o rep o rep o rep o rep o rep o
  6. 6. Git branching model Master branch Hotfixes Dev. branch Release 1.0 Feature branches TIM E Tag 0.1 Tag 0.2 Tag 1.0
  7. 7. How to begin using Git?
  8. 8. Installation
  9. 9. Setup $git config --global user.name "Your Name" $git config --global user.email "your@email.com" $git config --global color.diff auto $git config --global color.status auto $git config --global color.branch auto
  10. 10. Initialization $cd /l/vhosts/os.htdocs/example $ls $git init Go to the source code Are we really there? Create Git repository
  11. 11. Fork existing repository $git clone git://github.com/dsheiko/HTML5-Form- Shim.git
  12. 12. Commit $git commit –am “comment”
  13. 13. Status $git status
  14. 14. Reverting $git log $git checkout 64fd65b9194b108643e267795f9442ca9e61631f Get revisions ids Use one
  15. 15. Resetting $git reset HEAD --hard
  16. 16. Branching If we have a new feature request, which implementation concerns much of the source code, it would be safer to work on the feature in a separate branch. $git branch Feature1022 –m “Comment” $git checkout Feature1022 $git branch Create a branch Switch to the branch Show available branches
  17. 17. Rebase $git log $git rebase -i HEAD~7 Take a look what revisions we have Combine the last 7 revisions
  18. 18. Merging As we finished the requested feature development, we can merge the feature branch with the master branch $git checkout master $git merge Feature1022 $git branch -d Feature1022 Master branch Feature1022 Switch to the master branch Get rid of the feature branch
  19. 19. Tagging We can tag specific points in history as being important. E.g. tag every stable version of the product before deploying. $git tag v1.1 –m “Comment” $git checkout tags/v1.1 $git tag $git tag –d v.1.1 $git push remote :refs/tags/v.1.1 Create a tag Switch to the tag Show available tags Remote tag in local repo Remote tag in remote repo
  20. 20. Log We can see our commit history $git log --graph .. and much fancier $gitk --all
  21. 21. Working with a remote repo Let’s associate our local repo to the new created remote repo $cd /repos/example-remote $git init --bare $cd /l/vhosts/os.htdocs/example $git remote add origin /repos/example-remote
  22. 22. Push changes to a remote repo We can push our changes collected in the local repository to the remote one to share them with the team $cd /l/vhosts/os.htdocs/example $git push origin master Associated remote repo Branch
  23. 23. Pull changes from a remote repo Pull allows us to get the latest changes from the remote repository. $cd /l/vhosts/os.htdocs/example $git pull origin master
  24. 24. Creating patches Patch is a text file that contains changes to the source code. This file can be sent to someone else and this person can use this file to apply the changes to his/her local $git checkout mybranch $git commit -am "First commit in the branch“ $git format-patch origin/master $git checkout master $git apply 0001-First-commit-in-the-branch.patch Creates 0001-First-commit-in-the- branch.patch
  25. 25. Git command aliases Put into .gitconfig anywhere in parent directory with following content: [alias] cd = checkout dir = branch ci = commit -a -m lg = log -p undo = reset –hard up = !git push origin master && git push origin --tags
  26. 26. Git command aliases Now you can use shortcuts: $git cd SomeBranch $git dir $git ci “my comment“ $git up # this one pushes local commits and tags to the remote repo
  27. 27. Who’s the dude? http://dsheiko.com @sheiko https://github.com/dsheik