git
TRANSCRIPT
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 1
Git Training & Support Doc.
Rajesh Tripurneni
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2
PreReqs• If on StarOS machine add Git executable to your path
export PATH=$PATH:/auto/mitg-sw/tools/debian/git/bin
• Add your public key to Gitolite from a machine that has access to http://wwwin-mitg-releng.cisco.com
/auto/mitg-sw/oak/bin/git-request-access (git request-access)
• Verify your accessssh mitgscm@mitg-git info | grep perf | grep -v autotest
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 3
Basic Workflow• Create clone
Clones all branches but checks out only 1 at a time
• Make some changes
• Add changes to staging area (index)
• Commit changesSubmit changes for PRRQ review at this point
• Push changes to server*Git will notify you if you have to pull before push to get most recent changes and merge may be required$ git push
• Periodically update release file, commit, apply tag and push update from perftest-staging to perftest
Operation is restricted to authorized users
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 4
Branches• 3 Types
Topic
Local
Tracking
• Conventionsbitkeeper/.* : Bitkeeper imports
dev/.* : Development branches
merge/.* : Merge branches
jenkins/.* : Jenkins last good build branches
.* : Official Releng managed branches (e.g., master)
• Creating a dev branch$ git checkout –b dev/<some_name> <optional commit #/branch/tag>
$ git push –u origin dev/<some_name>
• Checking out a local branch$ git checkout <branch name>
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 5
Tags• Pointer to a commit to identify interesting state
Doesn’t move once applied
Can be simple or annotated
$ git tag (list)
$ git tag -a -m “Tag Message” <tag name>
• Doesn’t get pushed to server with regular ‘git push’$ git push --tags (push all tags)$ git push origin <tag name>
$ git push $REPO_URL <tag name>
• Branch data and tag data have to be pushed separatelyPushing tag will not update branch head with commits up through tag
• Script to update perftest-staging/bin/release and apply tag/auto/mitg-sw/tools/bin/git-tag-perf$ git tag-perf -t release-1.1.6
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 6
Hooks• Equivalent to BK triggers
• Clientpre-commit: Check for non-ascii filenames and merge markers left in files
commit-msg: Check for CDETS ID only on command line and add CDETS Headline if found
post-commit: Warn if no CDETS and suggest ‘git commit --amend’
post-checkout: Submodule processing
post-merge: Submodule processing
• Serverpost-receive: Calls cdets and email hooks on official branches only
post-receive-cdets: Add CDETS Enclosure for commits with CDETS in msg
post-receive-email: Send push notification to configured email alias
• Perftest BK triggers implemented by Releng as Gitolite access and push notification rules and new ‘git tag-perf’ script
Releng will maintain both of these
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 7
Cloning a Server Repository• Use MITG ‘git-ws’ script to clone your repository and set up client
side hooksSets required git configuration valuesCreates local cache clone if cloning to local diskPopulates clone with client hooks (equiv of bk triggers)
• Ignore ‘repository cache’ warning if cloning to non-local disk
• Clone from default branch (master)$ git ws qa/perftest-staging perftest-staging
• Clone from specific branch$ git ws --branch dev/docon_work qa/perftest-staging pfstage_docon_work
• Clone from tagNote: This will result in a detached head (no branch) which is ok if you do not intend to make changes$ git ws --tag release-1.1.5 qa/perftest perftest
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 8
Clone Status• To check status of your clone use ‘git status’
$ git status
Local commit
Staged for commit
Modified but not yet staged with ‘git add’
New file not yet versioned
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 9
Environment Setup• Bash Auto-completion
• Display branch in command line prompt
• Git ConfigurationGlobal (--global) vs. local
$ git config -l (list)
• Git Gui Edit Options
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 10
Making Changes• To create new files or modify already-versioned files simply use
your favorite editor (files are writable by default)
• To change permissions use unix ‘chmod’ command$ chmod a+x sysEngine
• To create a symlink use unix ‘ln -s’ command
• To remove a file use ‘git rm <filename>’Removals are automatically added to staging by ‘git rm’
• To have Git ignore files you don’t ever want to version add then to .gitignore in the workspace root or at any level
.gitignore is versioned and accepts pattern matching
Releng to populate .gitignore with ‘bk ignore’ results from each repo
• Uncommitted changes are not associated with any branch
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 11
Staging Changes• Staging a change tells Git what to commit during the next
execution of ‘git commit’
• Also referred to as ‘Adding to the Index’ or ‘Adding to the cache’
• Can be done from command line$ git add <filename(s)>$ git add .
• Can also be done from ‘git gui’ by clicking on the file icon in ‘Unstaged Changes’ section
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 12
Committing Changes• Committing a change tells Git what will get pushed to the server during the
next ‘git push’ operation
• Can be done from command line$ git commit (will open an editor to type commit message)
$ git commit -m “<Commit Message>”
$ git commit --amend (amend commit message of last local commit)
• Can also be done from Git GUI by filling in Commit message Box and clicking ‘commit’ button.
• First time you attempt to commit from a StarOS machine with only a CDETS ID in the commit message you may see the following error. Simply try again and it should work from that point on.
The authenticity of host 'mitg-git.esl.cisco.com (<ip address>)' can't be established.RSA key fingerprint is <fingerprint>.Are you sure you want to continue connecting (yes/no)? yesERROR - Invalid CDETS id: <CDETS ID you used>Aborting commit due to empty commit message.
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 13
Diffs• Diff of modifications to working tree
$ git diff
• Diff of staged changes$ git diff --cached
• Diff of local commitsDiff commits reachable from local branch HEAD but not reachable from tracking branch
$ git diff origin/master..HEAD
• Diff of all local changes$ git diff origin/master
• To generate diff for PRRQ use git-review command or as of August 1 configure your PRRQ queue to use Git for SCM
git-review will not work from StarOS machines
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 14
Submitting Diffs to PRRQ• MITG-Releng git-review script does not work from StarOS
because it relies on PRRQ command line interface tools in /usr/cisco/bin
• The PRRQ Team should be releasing support for Git on August 1Auto-collect diffs from Git workspace based on supplied diff options
Queue must be configured to accept Git as ‘Source Code Management System Interface’
Side-by-Side display issues with IE
• When creating review or uploading new diff, auto-collect from Git
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 15
Merges• Pull history/commits from one branch into another
$ git checkout <dest branch>
$ git merge <src branch>
Resolve conflicts and ‘git add’/’git commit’
• Update master with latest changes from bitkeeper/master$ git checkout master
$ git merge bitkeeper/master
• Conflict resolution$ git config --global merge.tool tkdiff
$ git config --global mergetool.tkdiff.trustExitCode false
$ git mergetool <-y>
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 16
Viewing History• Command Line
$ git log <options>$ git log --grep=CSCub27153$ git log --since=14-MAY-2013$ git log --author=psanborn
• Showing specific commit information$ git show 4f17c57d724e6c59b9b82bc1425c3eaa1da3e0b3$ git show release-1.1.4$ git show release-1.1.4:bin/atsEngine.pl
• Graphically$ gitK
Available from ‘git gui’ via RepositoryBrowse <branch> files
• On the Server with GitWebhttp://mitg-git:15690/
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 17
Pushing to Perftest Production• qa/perftest is the production repository
• Authorized users periodically push from qa/perftest-staging to qa/perftest after updating bin/release file and applying a tag
$ git tag-perf -t release-1.1.6
• Master branch and latest tag push separately$ git checkout master
$ git push mitgscm@mitg-git:qa/perftest
$ git push mitgscm@mitg-git:qa/perftest <tag>
• Can opt to push both from Git GuiSelect Source BranchSelect ‘Arbitrary location’ and fill in mitgscm@mitg-git:qa/perftest
Select ‘Include tags’
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 18
Gotchas• Git GUI, gitk and tkdiff for mergtool require TCL 8.4 and StarOS
machines missing /usr/bin/wish8.4 will fail to invoke (e.g., smoke1-vm1, but wily1-vm1 works)
• Some StarOS systems produce ‘Protocol mismatch’ error attempting to get to releng website when running ‘git request access’
• Meld we built does not work on StarOS machines (use tkdiff instead)
• BK allows BK add in a git repositoryRetrieving file mistakenly removed with 'bk add'
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 19
Official Cutover from BK• Releng regularly importing changes from BK to Git repos
• Releng will maintain access rights to ‘master’ branch of each repository and to release tag creation in perftest and perftest-staging
Open RER of type ‘Other’ to request modifications of rights
• Bitkeeper perfinfra repository was locked on 7/26/2013Releng created ‘master’ branch from bitkeeper/master and made ‘master’ the default branch.
Permission to push updates to ‘master’ restricted to particular users
All new work in perfinfra should be performed in Git clone
• BitKeeper perftest and perftest-staging repositories will be locked August 16Until then, create ‘dev/’ branch to play on
Final import of BK perftest-staging into Git on Aug 16 after lock
Releng will update Git perftest from perftest-staging
Releng will create ‘master’ branch in perftest and perftest-staging from which all new work will be submitted
Releng will add .gitignore to perftest and perftest-staging
© 2010 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 20
Resources• git help <command name>
• Cheat Sheet
• FAQ
• Using QA Repositories During Migration Period
• Pro Git Book
• Session 1
Thank you.