Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to VCS and Git

Introduction to VCS and Git

Alexey Buzdin

October 14, 2015
Tweet

More Decks by Alexey Buzdin

Other Decks in Programming

Transcript

  1. Version Control System • Tool for managing a *collection of

    files and its content. • *Collection is called a Repository
  2. When to VCS? • Almost every time you write code!

    • Great even for a single file
  3. Git is a DVCS • Everything is done locally (check

    in / commit / branch / merge) • Collaboration via repository sync • Peer to Peer approach (all repo are equal) • Stores history locally (Distributed Version Control System)
  4. Pros and Cons • Fast revision checkout • Offline usage

    • Local commits • Full control over VCS • Binary snapshot history • Repos can be heavy on first checkout due to local history • Hard to master
  5. Configure Git Credentials: • git config —global user.name alexey.buzdin •

    git config —global user.email [email protected] ~/.gitconfig - global REPO/.git/config - local
  6. [merge] tool = p4merge keepBackup = false [mergetool "p4merge"] cmd

    = p4merge "$BASE" "$LOCAL" "$REMOTE" "$MERGED" keepTemporaries = false trustExitCode = false keepBackup = false prompt = false [difftool] external = p4diff [push] default = current [credential] helper = osxkeychain [branch] autosetuprebase = always [user] name = alexey.buzdin email = [email protected] [mergetool] keepBackup = false prompt = false [alias] st = status [core] autocrlf = input excludesfile = /Users/alexeybuzdin/.gitignore_global [difftool "sourcetree"] cmd = opendiff \"$LOCAL\" \"$REMOTE\" path = [mergetool "sourcetree"] cmd = /Applications/SourceTree.app/Contents/Resources/opendiff-w.sh \"$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merg \"$MERGED\" trustExitCode = true vim ~/.gitconfig
  7. .gitignore # NuGet dependencies packages/ # Android module specifics **/Resource.designer.cs

    # Shared files **/bin/ **/obj/ *_ReSharper.*/ # Misc files *.user *.suo *.userprefs *.DS_Store *.swp # Migration .svn
  8. New Git Project • mkdir git-introduction; cd git-introduction • git

    init • git remote add origin https://github.com/LArchaon/learning-git-repo.git • git fetch • git checkout master
  9. New Git Project • mkdir git-introduction; cd git-introduction • git

    init • git remote add origin https://github.com/LArchaon/learning-git-repo.git • git fetch • git checkout master or • git clone https://github.com/LArchaon/learning-git-repo.git
  10. Example • echo "Hello World" > a.txt • git status

    • git add a.txt • git status • git commit -m ”Initial commit” • git status • ???
  11. Navigation • git checkout 98ca9 • git checkout master •

    git checkout v1.0 • git checkout @ or git checkout HEAD
  12. Merging Pros • Simple to use and understand. • Maintains

    the original context of the source branch. • The commits on the source branch remain separate from other branch commits. This separation can be useful in the case of feature branches, where you might want to take a feature and merge it into another branch later. • Existing commits on the source branch are unchanged and remain valid; it doesn’t matter if they’ve been shared with others.
  13. Merging Cons • If the need to merge arises simply

    because multiple people are working on the same branch in parallel, the merges don’t serve any useful historic purpose and create clutter.
  14. Rebase Pros • Simplifies your history. • Is the most

    intuitive and clutter-free way to combine commits from multiple developers in a shared branch
  15. Rebase Cons • Slightly more complex, especially under conflict conditions.

    Each commit is rebased in order, and a conflict will interrupt the process of rebasing multiple commits. With a conflict, you have to resolve the conflict in order to continue the rebase. • Rewriting of history has ramifications if you’ve previously pushed those commits elsewhere.
  16. more!!! “Check out the client branch, figure out the patches

    from the common ancestor of the client and server branches, and then replay them onto master.”
  17. Success! • git checkout master • git merge server •

    git branch -d client • git branch -d server
  18. • …. • git commit -m ”My commit” • git

    stash • git pull --rebase • git push • git stash apply