Successfully reported this slideshow.

Git Aliases of the Gods!

2

Share

Upcoming SlideShare
Git basics
Git basics
Loading in …3
×
1 of 49
1 of 49

Git Aliases of the Gods!

2

Share

Download to read offline

Git's incredible velocity and iron-clad backwards compatibility are a paradox: how does a CLI tool introduce hundreds of new features without changing its existing behavior? With command-line options, of course! The downside is that Git now has literally thousands of options littering its man pages. The only way to master them is through the ancient art of aliasing. This talk covers the nuts and bolts of creating Git aliases and automating Git-related JIRA and Bitbucket interactions from the command line. Attendees will learn tips and tricks for speeding up their workflow, improving their CLI mastery, and they'll also learn a lot about Git in the process.

Tim Pettersen, Senior Developer Advocate, Atlassian

Git's incredible velocity and iron-clad backwards compatibility are a paradox: how does a CLI tool introduce hundreds of new features without changing its existing behavior? With command-line options, of course! The downside is that Git now has literally thousands of options littering its man pages. The only way to master them is through the ancient art of aliasing. This talk covers the nuts and bolts of creating Git aliases and automating Git-related JIRA and Bitbucket interactions from the command line. Attendees will learn tips and tricks for speeding up their workflow, improving their CLI mastery, and they'll also learn a lot about Git in the process.

Tim Pettersen, Senior Developer Advocate, Atlassian

More Related Content

Related Books

Free with a 14 day trial from Scribd

See all

Related Audiobooks

Free with a 14 day trial from Scribd

See all

Git Aliases of the Gods!

  1. 1. Git aliases of the gods! TIM PETTERSEN | SENIOR DEVELOPER | ATLASSIAN | @KANNONBOY
  2. 2. ALIASES $ git config --global alias.ci commit # equivalent to `git commit` $ git ci $ git config --global alias.$name $command
  3. 3. ALIASES
  4. 4. GIT STASH $ echo “work work work work work work” >> work.txt $ git stash $ git status $ git stash pop Saved working directory and index state WIP … nothing to commit, working tree clean Changes to be committed: modified: work.txt
  5. 5. GIT STASH $ echo “new stuff” > new.txt 🤔No local changes to save $ git stash $ git status Untracked files: new.txt
  6. 6. GIT STASH unstaged changes to tracked files staged changes to tracked files untracked files ignored files git stash
  7. 7. GIT STASH $ echo “new stuff” > new.txt 🤔--include-untracked No local changes to save $ git stash $ git status Saved working directory and index state WIP … Untracked files: new.txt nothing to commit, working tree clean
  8. 8. GIT STASH unstaged changes to tracked files staged changes to tracked files untracked files ignored files --keep-index git stash --include-untracked --all
  9. 9. GIT STA{0,3}SH $ git config --global alias.stsh ‘stash --keep-index’ $ git config --global alias.staash ‘stash --include-untracked’ $ git config --global alias.staaash ‘stash --all’ $ git stsh # unstaged $ git stash # unstaged + staged $ git staash # unstaged + staged + untracked $ git staaash # unstaged + staged + untracked + ignored
  10. 10. Why alias? Save time Encapsulate options Chain commands Share your wizardry
  11. 11. WHICH BRANCH? [alias] staaash = stash --all which = !git branch | grep -i $ git which JIRA-7 feature/JIRA-7-reactor-refactor release/JIRA-7.0 $ cat ~/.gitconfig JIRA-7
  12. 12. GIT LUCKY sh -c ‘ ’ which = !git branch | grep -i git checkout $(git which $1 -m1)lucky = [alias] ! $ git lucky JIRA-7 Switched to branch ‘feature/JIRA-7-reactor-refactor’ -
  13. 13. GIT STANDUP [alias] standup = !git log --all --author=$USER --since=‘9am yesterday’ --format=%s
  14. 14. GIT STANDUP $ git standup Fix format of `git standup` command Document which and lucky Document the pipelines alias wrap at 80 chars Add git serve alias Use vanilla ! format for standup alias
  15. 15. GIT LAZY-STANDUP [alias] standup = !git log --all --author=$USER --since=‘9am yesterday’ --format=%s lazy-standup = !git standup | say
  16. 16. D V C S
  17. 17. GIT DAEMON [alias] serve = daemon --reuseaddr --verbose --base-path=. --export-all ./.git 👹 $ git serve Alias source: https://git.wiki.kernel.org/index.php/Aliases [39113] Ready to rumble
  18. 18. Image credit: ngrok.com ngrok
  19. 19. GIT NGROK $ git ngrok [31074] Ready to rumble Serving your repo at: git://0.tcp.ngrok.io:17720/ Press any key to tear down... $ git clone git://0.tcp.ngrok.io:17720/ my-repo Cloning into ‘my-repo'... Waiting for git daemon and ngrok to start...
  20. 20. GIT NGROK [alias] ngrok = “!f() { git serve & ngrok tcp 9418 & }; f“
  21. 21. GIT NGROK [alias] ngrok = “!f() { git serve & ngrok tcp 9418 & curl -s …/api/tunnels/command_line | jq -r ‘.public_url’; read -rsp ‘Press key to tear down’ k; pkill -P $$; }; f“ Awesome for parsing JSON in scripts
  22. 22. Wait a second…
  23. 23. THAT’STHAT’S BASH!BASH!
  24. 24. Context and namespacing WHEN SHOULD I ALIAS? Git aliases are for Git operations. Bash aliases run anywhere. If it doesn’t use a Git command (or touch .git/) it probably shouldn’t be a Git alias.
  25. 25. BITBUCKET PIPELINES $ cat bitbucket-pipelines.yml pipelines: image: node:4.6.0 default: - step: script: - npm test
  26. 26. BITBUCKET PIPELINES $ cat bitbucket-pipelines.yml pipelines: image: node:4.6.0 custom: deploy: - step: script: - ./deploy-to-prod.sh
  27. 27. GIT PIPELINE $ git pipeline deploy 7e2aef8 $ git pipeline docs v3.1.0 $ git pipeline sonar feature/JIRA-123
  28. 28. GIT REV-PARSE $ git rev-parse 7e2aef8 7e2aef80c173efa8bebfd19b10b93f40f2da03b9
  29. 29. PARSING “COMMIT-ISH” rev-parse 7e2aef80c173efa8bebfd19b10b93f40f2da03b9 7e2aef8 feature/JIRA-123 master@{yesterday} bd4a417~2 v3.1.0
  30. 30. GIT REV-LIST $ git rev-list 7e2aef8~3..7e2aef8 7e2aef80c173efa8bebfd19b10b93f40f2da03b9 d3c70a8678ac7ef1a82caeedc23d51fb4714a70c 443ec224b5a8c64abe20f376070d3b1196865f30
  31. 31. GIT PIPELINES $ git pipelines test 7e2aef8~3..7e2aef8
  32. 32. master origin/master
  33. 33. FIND A REGRESSION $ git bisect $broken_commit $green_build O(log n) t * log n
  34. 34. FIND A REGRESSION $ pipelines test $green_build..$broken_commitgit t$ git pipelines test origin/master{1}..origin/master{0}
  35. 35. Env validation Dependency checks Embedded JSON
  36. 36. GIT SCRIPTS $ PATH=$PATH:~/git-scripts $ cat ~/git-scripts/git-my-cool-script $ git my-cool-script #!/usr/bin/env … nodepythonruby
  37. 37. GIT SHAM $ git sham <regex> $ git sham ^414 $ git commit -m “Bitbucket Server v4.14” f4fc63521f56 Bitbucket Server 4.14 414ab621c557 Bitbucket Server 4.14 🗽🎖🌦
  38. 38. JIRA-GIT $ npm install -g jira-git $ git jira --configure # to configure $ git jira -h # help! # to install
  39. 39. SHARING ALIASES $ cat ~/.gitconfig [include] path = ~/git-aliases/.gitaliases $ git clone https://bitbucket.org/tpettersen/git-aliases
  40. 40. Custom actions in SourceTree
  41. 41. Git aliases of the gods! Save time Encapsulate options Chain commands Share your wizardry
  42. 42. GIT ALIASES OF THE GODS! bit.ly/git-aliasthe aliases: ngrok: ngrok.com jq: jqplay.org git sham: jira git: bit.ly/jira-git bit.ly/git-sham me: @kannonboy (Don’t do it!)
  43. 43. Thanks! TIM PETTERSEN | SENIOR DEVELOPER | ATLASSIAN | @KANNONBOY Questions?

×