My previous post was to introduce git, this one is for CLI update/note:
REMOTE
$ git init ProjectName.git --bare
(create remote empty git repo as origin master to push)
$ git push --set-upstream origin BranchName.
(To push the current branch and set the remote as upstream)
$ git push -u origin myBranchName
$ git remote -v
(List remote repo)
$ git remote add <name> <url>
(add remote repo <name> = “origin”, url = server.com:/where/the/project.git)
FILE
$ git checkout --filename.ext
(remove the file filename.ext from git)
$ git status
(show current status of git, I execute it before git add .)
$ git restore filename.ext
(before commit, restore the file to previous status, even file is saved, the content is back to the before)
CLEAN UP GIT
$ git clean -df projectName
(clean up git)
HEAD
$ git log --oneline --graph
(show list of commit.)
$ git reset --hard HEAD
(go to current HEAD.)
$ git reset --hard HEAD
^ (go back to the 1 commit from current HEAD.)
$ git reset --hard HEAD~2
(go back to the 2 commits from current HEAD.)
$ git reset --hard index
(go back to the commit where the index is)
UPDATED 09/16/2021
Just encounter an accident, so I’m updating the post.
Accidentally overwritten a file!! OMG. A awesome thing about git is you can retrieve a file or files later. Usually right after you save a file and notice a mistake and Ooops, I shouldn’t save the file, in stead save as different file name. Anyway if you saved and noticed, means you have not git commit the change. So simply:
$ git status
(show status what has been modified)
$ git restore fileName
(restore the file)
IMPORTANT: Once you notice, you need to change the file name before do git restore, so you can have both.
If you’ve already git add . + committed, you should use
git reset --hard HEAD
^ (go back to the 1 commit from current HEAD.)
IMPORTANT: before git reset, always nice to have a current backup somewhere else in local or remote.
UPDATED 06/09/2022
find remote branch names
$ git remote -v show origin
pull the remote branch
$ git pull branch-name