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

Git Real (Tips & Tricks on Git)

Git Real (Tips & Tricks on Git)

and other stuff...

Dominik Hádl

April 13, 2016
Tweet

More Decks by Dominik Hádl

Other Decks in Technology

Transcript

  1. # Adding git add -A git add MyFile.txt # Removing

    git reset * git reset MyFile.txt
  2. # Move a commit to different branch git reset --soft

    a6fe6eb git checkout -b FeatureBranch git commit -m "Added my feature"
  3. # Remove file from index, but keep on disk #

    (ie mark it as deleted for git and stop tracking it) git rm --cached MyFile.txt # Remove file from index and from disk git rm MyFile.txt # Mistake? Undo? Careful now. git reset --hard HEAD
  4. Already pushed? # CAREFUL git push origin master --force #

    Bonus - delete a remote branch git push origin :BranchName
  5. # Quick and better option of saving git stash git

    stash save "Changes in documentation" # List, show or clear stashes git stash list git stash show stash@{0} git stash clear # Use your stash git stash branch "DifferentBranch" git stash pop # ^^ (git stash apply && git stash drop)
  6. Update your feature branch with changes from upstream. Don’t create

    unnecessary commits and clutter history/log. Proves you have better understanding of git. Do magic with --interactive option Why use rebase?
  7. # HEAD~3 = HEAD commit + number of previous commits

    git rebase -i HEAD~3 pick 5afdd30 more files reword ed8ad23 More jizzy files pick 8e6b89d trying some fix fixup fa167e2 maybe this works??? # Rebase 35f4454..fbc34fb onto 35f4454 (4 command(s)) # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # d, drop = remove commit
  8. # Add a tag git tag -a 0.0.1 -m "My

    tag name" # Delete a tag git tag -d 0.0.1 # Push a tag git push origin master --tags # Delete tag from remote (GitHub) git push origin :refs/tags/0.0.1 Always respect SEMVER .
  9. .gitignore (please add this) Saves time for others. Prevents accidental

    addition of files to git. Shows that you care about other people.
  10. .gitconfig (some tricks) [alias] co = checkout cm = commit

    p = push a = add -A ac = !git add -A && git commit st = status -sb [url "[email protected]:"] insteadOf = "gh:" pushInsteadOf = "github:" pushInsteadOf = “git://github.com/" [url "git://github.com/"] insteadOf = “github:" [url "[email protected]:"] insteadOf = "gst:" pushInsteadOf = "gist:" pushInsteadOf = “git://gist.github.com/" [url "git://gist.github.com/"] insteadOf = “gist:" [url "[email protected]:"] insteadOf = "heroku:"
  11. SCM Breeze (must have!) # cd to local repo c

    Project1 c NodesFramework # Even quicker commands gc -m "" # git commit gl # nice git log gs # status ga 1 # add files by index!
  12. Why UI sucks? Options from command line are usually not

    available. Some (Xcode, Android Studio…) even miss basic features. In case some error happens, you get a weird non descriptive message and you’re not sure which command was actually executed.
  13. Github (from command line) These GitHub commands are provided by

    hub: pull-request Open a pull request on GitHub fork Make a fork of a remote repository on GitHub and add as remote create Create this repository on GitHub and add GitHub as origin browse Open a GitHub page in the default browser compare Open a compare page on GitHub release List or create releases (beta) issue List or create issues (beta) ci-status Show the CI status of a commit brew install hub