Baisc Git operation tutorial, use terminal


Setting your information:

  • Set information

    git config —global user.name “Your name”
    git config —global user.email “Your email”
  • Remove information

    git config --global --remove-section user.name
    git config --global --remove-section user.email

    git flow

basic command:

Create an git repo

git init

Check what file can add to your repo

git status

Tell git which of the files to place into version control (Avoid adding confidential information like api key, db password etc.)

git add <~/your/files/path/first_file> <~/your/files/path/second_file2>
git add . #**Put all files into version control**

Commit all file that have been adding, put something message

git commit -m “message you want to put”

Add remote need two args

  1. A remote name like ‘origin’
  2. A remote URL like ‘https://github.com/Natsusaka0505/Natsusaka-blog.git’
git remote add origin <https://url/owner.repo.git>

Copy an existing git repo from a server to local machine

  • URL method:
    git clone <https://url/owner.repo.git> <Name you to rename>
  • SSH method:
    git clone <[email protected]:username/projectname.git>

Push your code and file from local to remote

git push -u origin <branch>

How to set up remote

  • Check git remote information
    git remote -v
  • What’s is upstream
    • “upstream” refer to the main branch from which a given branch was branched off of.
    • The git default use “origin” as the remotee name.
  • Set remote upstream url
    git remote set -url upstream <https://url/owner.repo.git>

Other command

Check the codes difference

- git diff <file>

Get all local available information

git status