Skip to content

git cmd #13

Description

@etaf

push local code to new created repo

$ git init
$ vim .gitignore
$ git add -A
$ git commit -m "init"
$ git remote add origin https://etaf@github.... 
$ git push origin master

remote file from git repo

$ git rm file
$ git rm -r dir

added but not commit, rm file added:

$ git rm --cached file

force replace local code with server code:

$ git reset --hard
$ git pull origin master

cheate a new branch and switch to it:

$ git checkout -b branch-name

push local branch to remote server:

$ git push origin branch-name

fetch remote branch from remote server:

$ git fetch origin

replace local branch with server branch:

$ git reset --hard HEAD~3         # HEAD~3 means rollback 3 commit versions
$ git pull

if you make a mistake when using: git reset --hard , then the commits before it would lose(see git log), how to recover them ?

$ git reflog
$ git reset --hard  <sha>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions