MKimiSH

Xianyao Zhang

Git Tips

This post is mainly a reminder of some errors I have encountered with Git. Writting things down may help me avoid recurrent errors :)

GIT push: permission denied (public key)

  • Happened when I wanted to git push.
  • stackoverflow
  • Need to set up the SSH key and add it to Github (or wherever your remote is).
  • I was surprised when finding out that I didn’t do it on my laptop!

src refspec master does not match any.

  • Happened when I wanted to git push. When creating my github.io repo, I didn’t follow the process of forking the template and then modifying. I cloned the original repo, modified it and then wanted to push to the origin to the empty github.io repo that I created. At first it didn’t work because the origin still points to the original repo which of course I cannot write to. Then I changed the origin by git remote set-url and it gave me this error. I thought it was because of not forking the repo, so I followed the recommended path again. But this error still persisted.
  • stackoverflow
  • Turned out that the forked repo did not have the master branch, only a gh-pages branch. I need to specify the branch name…

Miscellaneous

  • show changes on a file before commit, before/after add git diff file shows diff of a file from the previous commit. git diff --cached file after add
  • show refs: git show-ref
  • git clone submodules git clone --recurse-submodules -j8 git://github.com/foo/bar.git
  • update submodules: commit in submodule, push in submodule, commit in main repo, push in main repo. (not validated yet)
  • git push <remote_name> --delete <branch_name> deletes a remote branch. git branch -d/-D <branch_name> deletes a local branch. -D forces the delete.
  • git cherry-pick <commit> applys the changes introduced by commit on top of the current branch. I used that a lot. Probably it is very bad…
  • git config --global alias.co checkout set a global git shorthand.

(Background image credit: video)