Most Used Commands on Git

Initial git repository on current directory
$ git init

Download a project from GitHub/GitLab
$ git clone [url]

Configure your personal information
$ git config --global user.name "Nick Yang"
$ git config --global user.email "your_email@example.com"

Add .gitignore file (generate .gitignore)
$ git config --global core.excludesfile ~/your_file

Add file to area
$ git add [file]

Remove file from Git
$ git rm [file]

Committing Your Changes
$ git commit

Revise last commit
$ git commit --amend

Clear stagging area
$ git checkout -- .

New a branch B from A
$ git checkout -b [B] [A]

Switch to branch A
$ git checkout [A]

Merge branch B to A
$ git merge --no-ff [B]

Tag on current commit
$ git tag [tag_name]

Submmit tag to server side
$ git push [remote] [tag]

Submmit project A
$ git push origin [A]

Delete branch A
$ git branch -d [A]

Store changing, but not commit
$ git stash

List stash
$ git stash list

Applying stash@{2}
$ git stash apply [stash@{2}]

Cancel stash@{2}
$ git stash show -p [stash@{2}] | git apply -R

Remove stash@{2}
$ git stash drop [stash@{2}]

git command tutorial
$ git --help [command]

No comments:

Post a Comment