Useful git commands
Apr 12, 2021
add remote url:
git remote add origin https://code.taou.com/git/shaokaining/features-register.git
set remote url:
git remote set-url origin
set upstream
git branch --set-upstream-to=origin/master
Reset local repo to be exactly the same as remote repo
git fetch
git reset — hard origin/master
reset a single file to a branch
git checkout origin/master [filename]
Compare a file with the remote branch
If [remote-path]
and [local-path]
are the same, you can do
$ git fetch origin master
$ git diff origin/master -- [local-path]
Note 1: The second command above will compare against the locally stored remote tracking branch. The fetch command is required to update the remote tracking branch to be in sync with the contents of the remote server. Alternatively, you can just do
$ git diff master:<path-or-file-name>
Note 2: master
can be replaced in the above examples with any branch name