It is a Git guideline for myself 🤔

There are Three part of it

  • 🔗Build a connect from Local to Remote
  • 📖Clone repo from Remote to Local
  • 💡Some little tip about git

🔴Part 1. Build a connect from Local to Remote

First: creat a work directory and init it

    1. Creat a directory and name it anything you want
    1. Enter the cmd window and run this command
   git init
    1. Create a file or move code file in it, then add all this to buffer zone
   touch test.txt
   git add .
    1. Then make a commit to my local repo
   git commit -m "xxxx"                   xxxx is the remark to the change 

img_1.png

    1. Add the remote repo and name it, then use [-v] to check the detail
   git remote add origin [URL]
   git remote -v
   ATTENTION!!! always use origin as the name of repo

img_2.png

    1. Get the remote repo information and check the branch
    git fetch origin
    git branch -a

img_3.png

    1. Make a tracking branch as prepare work
    git branch -u origin/master master 
    
    ---the first param is remote while the second is local---
    git branch -vv      [check the tracking information]
    1. Then pull the repo to update branch
    git pull --allow-unrelated-histories

img_4.png

    1. At last directly push the commit the remote repo (Since tracking has been set in step 7)
    git push

img_5.png

    1. 🤩 It can be checked on the repo commit column

img_6.png

🔴Part 2. Clone from remote repo and build cooperation

    1. Creat a directory and name it anything you want
    1. Enter the cmd window and run this command
    git clone [URL]

It will creat a .git directory with git configure in secret, and initialize it at the same time

    1. Then the repo can be successfully download

🔴Part 3. Some useful tips about git

1. The operation of branch

  • 1.1 Create a new branch
    git branch [branch_name]
  • 1.2 Switch to the branch
    git checkout [branch_name]
  • 1.3 Create a new branch and switch to it
    git checkout -b [branch_name]
  • 1.4 Merge the dev branch to the master branch
    git checkout master
    git merge dev

🔴🔴 Some Emergency Error

1. When there is a time pushing the commit to remote repo, it will show the error like this

fatal: unable to access 'https://github.com/xxxx': 
Failed to connect to github.com port 443 after 21039 ms: 
Could not connect to server

There are some solutions to solve this problem

    1. Disable the ssl verification (not recommended)
    git config --global http.sslVerify false
    1. Find the process that occupies the port 443 and kill it
    netstat -ano | findstr 443
    taskkill /F /PID [PID]

or batch operation

    for /f "tokens=5" %a in ('netstat -aon ^| findstr "443"') do taskkill /F /PID %a

2. "Could not connect to server" problem when push the commit

fatal: unable to access 'https://github.com/Linncharm/xxxxxx': 
Failed to connect to github.com port 443 after 21097 ms: Could not connect to server

Solution

    1. Cancel the http/https proxy setting of git
    git config --global --unset http.proxy
    git config --global --unset https.proxy
    1. Modify the git port same as local port img.png
    git config --global http.proxy http://127.0.0.1:4780