Few Commands About Use Git to Commit to GitHub

2016/4/13 min read
bookmark this
Responsive image

How to Use git to commit to GitHub

Following example is for windows enviroment and command is use windows' Command Prompt.

First you need to setup the git's user and email, check the current user and email by run following command.

> git config --list

If the user.name or user.emailis not there, try run following command to set username and email address.

> git config --global user.name "test"
> git config --global user.email "test.email"

Now, you're ready for git check-in locally, if you type git commit -m "test commit" for commit. Type git log, you'll see the log history of the git commit.

Init Git

Run this command to initialize the git.

> git init

Git local commit

> git add .
> git commit -m "Initialize repository"

Commit to GitHub

> git remote add origin {your github address}
> git push -u origin master

Clone Git from Github

> git clone {your github address}

Clone Git origin url A then Check-in to Git origin url B

> git clone {url A}
> delete git folder
> git remote set-url origin {url B}
> git pull {url B}
> git push -u origin master

In case of Git push doesn't work, and you tried possible solution already, then you could also try git push --force, to force update to the remote location.

List of Other Command

> rmdir {folder name} /s

List of Git command

  • git config --list
  • git config --get remote.origin.url
    • check current git repository's remote url
  • git config --global user.name "{your name}"
  • git config --global user.email "{your email}"
  • git init - use git for current folder
  • git commit "commit message"
  • git commit -m "commit comment, message must in one line"
  • git commit --amend -m "commit message" - append previous commit
  • git remote add origin "{Github address}"
  • git push -u origin master
  • git log
  • git log --oneline pretty view for the log
  • git status
  • git checkout --{file name}
  • git diff want to know where is the change
  • git diff --cached show what files had changed by commit
  • git reset HEAD cancel the git add
  • git config -lshow all the git config settings
  • git help configshow config help page
  • git merge --abort
    • undo merge