24
Git Tips and Tricks

Git Tips and Tricks

Embed Size (px)

Citation preview

Page 1: Git Tips and Tricks

Git Tips and Tricks

Page 2: Git Tips and Tricks

Disclaimer

• Not designed for someone who’s never used git before

• Designed for someone who is using it on a day-to-day basis, but want to know more about features available

• Only showing command-line approach

Page 3: Git Tips and Tricks

So what is git?

• Version Control System (VCS)• Allows you to store versions of a set of files• The change from one version to the next

version is a commit

3

Page 4: Git Tips and Tricks

git add -p

• Confirm each change before staging it for the next commit

• No more binding.pry in commits!

4

Page 5: Git Tips and Tricks
Page 6: Git Tips and Tricks

git stash save

• Save changes without adding them as a commit

• Useful if you need to change what you’re working on, or have too many changes for a single commit

6

Page 7: Git Tips and Tricks

Step 1: Too many changes

Page 8: Git Tips and Tricks

Step 2: Stage and commit one change

Page 9: Git Tips and Tricks

Step 3: Stage and commit other change

Page 10: Git Tips and Tricks

git blame

• Show when a line was last edited, and who did it

• (You can get the “why”, the commit message, with some extra parameters)

10

Page 11: Git Tips and Tricks
Page 12: Git Tips and Tricks

git log -p

• Don’t just provide the commit message:– SHOW ME TEH CODEZ

12

Page 13: Git Tips and Tricks
Page 14: Git Tips and Tricks

git commit --amend

• Something was wrong with the last commit:– You forgot a semicolon– You forgot a file– You need to change the commit

message

14

Page 15: Git Tips and Tricks
Page 16: Git Tips and Tricks

git reset --soft

• Sometimes, you’ve made a couple of commits, but they’re not that important. Just turn them into a single large commit.

16

Page 17: Git Tips and Tricks
Page 18: Git Tips and Tricks

git rebase -i

• Warning: Serious rewriting of history possible

18

Page 19: Git Tips and Tricks

git rebase -i (continued)

• This will show the safest scenario possible

19

Page 20: Git Tips and Tricks
Page 21: Git Tips and Tricks
Page 22: Git Tips and Tricks
Page 23: Git Tips and Tricks

Result

Page 24: Git Tips and Tricks

git bisect❖Find out what broke the build