Guangning Yu's Blog

Git Basics

2019-02-17 01:40:29  |  git
  • Setting user name and email
  1. git config --global user.name "Guangning Yu"
  2. git config --global user.email "hi@guangningyu.com"
  • Showing remotes
  1. git remote -v
  • Changing a remote’s URL
  1. git remote set-url origin git@github.com:guangningyu flasky.git
  • Pulling from remotes
  1. git pull origin master
  • Pushing to remotes
  1. git push origin master
  • Commit using default message
  1. git commit no-edit
  • Cancel last commit
  1. git reset HEAD~
  • Undo a git add
  1. git reset filename.txt
  • Define author & committer
  1. GIT_COMMITTER_NAME='Jane Doe' GIT_COMMITTER_EMAIL='jane@doe.com' git commit author="John Doe <john@doe.com>" -m "This is authored by John Doe and committed by Jane Doe."
  • Undo git rm
  1. git checkout HEAD path/to/file
  • Check out a remote branch
  1. git branch -a
  2. git checkout test_branch
  • Create a new branch
  1. git checkout -b [name_of_your_new_branch]
  • Push a local branch to remote
  1. git push -u origi