GETTING TO KNOW GIT: PART II JUSTIN ELLIOTT PENN STATE UNIVERSITY 1
REVERTING CHANGES 2
REVERTING CHANGES Change local files git reset git checkout Revert a commit in the branch history git revert Reset a file demo in SourceTree 3
STASH ING CHANGES 4
STASH TEMP CHANGES Saves changes to temporary area locally Does not create a commit to the repository Useful for switching to other branches without losing your work Restore the stash when ready to re-apply modifications Stash Demo in SourceTree 5
TAGS 6
TAGS Bookmarks a specific commit Useful for major version numbers Naming Conventions Label with version, Xojo Version, Plugin Versions, OS Version No white space permitted Converted from SVN will have %20 Tag demo in SourceTree 7
BRANCHES 8
BRANCHES Branches are a separate line of development A branch represents the tip of a series of commits Branches are just pointers to commits It's not a container for those commits 9
BRANCHES master is the default branch Help to separate lines of development Merging of branches is where Git excels GitFlow is a popular branching model Ex: Master, HotFix, Develop, Feature, Release 10
BRANCHES $ git checkout master Create and switch to new branch $ git checkout -b <branch> Delete branch $ git branch -d <branch> 11
BRANCH WALK THROUGH First Commit M1 12
BRANCH WALK THROUGH M1 B1 New Branch 13
BRANCH WALK THROUGH M1 B1 B2 Second Branch Commit 14
BRANCH WALK THROUGH M1 B1 B2 B3 Third Branch Commit 15
BRANCH WALK THROUGH M1 B1 B2 B3 B4 Fourth Branch Commit 16
BRANCH WALK THROUGH Merge Branch To Master M1 M2 B1 B2 B3 B4 (Branch Deleted After Merge) 17
DETACHED HEAD REFERENCE HEAD is a reference to latest commit in branch OR a specific commit Internally, the git checkout command simply updates the HEAD to point to either the specified branch or commit. The point is, your development should always take place on a branch never on a detached HEAD. This makes sure you always have a reference to your new commits. What does "detached HEAD" mean, and why should I care? Occurs when you check out a specific commit in a branch versus the latest commit of branch 18
GITFLOW BRANCHING MODEL 19
GITFLOW A successful Git branching model Only branch from and merge to the Master branch Master, HotFix, Release, Development, Features http://nvie.com/posts/a-successful-git-branchingmodel/ 20
GITFLOW: HOTFIX BRANCH First Commit C1 21
GITFLOW: HOTFIX BRANCH Second Commit C1 C2 22
GITFLOW: HOTFIX BRANCH Third Commit C1 C2 C3 23
GITFLOW: HOTFIX BRANCH C1 C2 C3 HF1 HotFix Branch Commit 24
GITFLOW: HOTFIX BRANCH Third (Merge) Commit C0 C1 C2 C3 HF1 25
GITFLOW: HOTFIX BRANCH Fourth Commit C0 C1 C2 C3 C4 HF1 26
REMOTES 27
REMOTE REPOS Local repo on your client only Remote is a Git host to push to You clone, push, fetch and pull from remotes 28
STANDARD GIT WORKFLOW Working Directory Staging Area Repository Remote 29
REMOTE REPOS Network Protocols SSH HTTPS Git Protocol (daemon) 30
SELF-HOSTED REPOS SSH Enable SSH, create bare repository on server Atlassian Stash Enterprise GitHub GitLab 31
REMOTE REPOS 3rd Party GitHub, BitBucket, Google Code CodeSpaces, SourceRepo Assembla, Gitorious And possibly more, I m betting! 32
CLONING A REPOSITORY The process of copying an existing Git repository to your computer A cloned repo includes the entire file history changes and commit messages Git clone command example: $ git clone https://server.edu/reponame.git 33
PUSHING CHANGES $ git push origin master Push (upload) the master branch to the origin remote host First remote is named origin Recommended not to rename this (GUI Apps assume naming convention) 34
GIT 2.0 PUSH DEFAULTS Starting with Git version 2.0 push will default to simple - push only the active branch you are on Previous behavior was to push all matching branches Could be dangerous, might miss that some branches updated without you remembering it $ git config --global push.default simple 35
FETCHING Fetching updates your local Git repo of the remote s status of commits, branches, tags Fetching from remote repo host does not change your local files Use when you want to update what your local Git repo knows about the remote s commits, branches, tags 36
REMOTES DEMO Create remote repo Add remote to local repo settings Local branches tracks remote branches Push full local repo to remote Commit locally, then push to origin remote Local branches and stashes never pushed to remote 37
DEBUGGING TOOLS 38
DEBUGGING WITH GIT File Annotation with git blame Use when you know where a bug is Binary Search with git bisect Very helpful when you can t determine which commit the bug was introduced 39
BISECT - BINARY SEARCH Bisect demo at the command line 40
LESSONS LEARNED 41
LESSONS LEARNED Learn the basics of the command line Helpful for when odd errors occur Access features not always available in GUI Apps 42
LESSONS LEARNED Embrace Branches Init project for GitFlow Use the Develop and HotFix branches to start Very easy to do in SourceTree 43
FOR MORE INFO 44
RESOURCES AND TRAINING Official Git Site http://git-scm.com Git Cheat Sheets Git Pro Book 45
RESOURCES AND TRAINING http://try.github.com http://atlassian.com/git O Reilly McCullough and Berglund on Mastering Git 46
THANK YOU. Justin Elliott jelliott [at] psu.edu! @justindelliott 47