menu

Git - Github - Gitlab notes

Posted on 28/11/2018, in Infomation Technology.

This note is used for my daily working routine with git.

  1. Set the information

      git config --global user.name "Dinh Anh Thi"
      git config --global user.email "[email protected]"
    
  2. Save github account as default

      git config credential.helper store
    

    then git pull for the first time input.

  3. Create a repository: git init <repo-name>
  4. Clone a repo (using HTTPS method): git clone <repo-link>
  5. Open git gui : git gui or gitk (they are different)
  6. Check the status: git status, git log --oneline --graph --color --all --decorate
  7. Discard the change: git checkout .
  8. Temporarily check a commit: git checkout <commitID>, if the work’s done, just check out back to the current working branch.
  9. Tạo nhánh mới:
  git checkout -b <ten-nhanh> # tạo và chuyển tới nhánh mới
  git branch <ten-nhanh> # tạo nhánh mới
  1. Xóa nhánh:
  git branch -d <ten-nhanh> # xóa nhánh local
  git push origin :<tên-nhánh> # xóa nhánh remote
  1. Liệt kê danh sách các nhánh
  git branch # local
  git branch -a # local & global
  1. Merge sub branch to master and replace master branch

      git checkout <nhanh>
      git merge -s ours master
      git checkout master
      git merge <nhanh>
    
  2. Working with branches

    • Compare 2 branches: git diff <src-branch> <compared-branch>
    • Delete: git branch -d <branch>
    • Delete (remove): git push --delete origin <branch>
    • Add description: git branch --edit-description (if you wanna exit Vim, press ESC then type :q to quit or :wq to quit and write)
  3. Error: Could not resolve host: github.com

      git config --global --unset http.proxy 
      git config --global --unset https.proxy
    
  4. Copy/update a folder from another branch to current branch. Suppose that we wanna copy folder abc from branch test5 to current brach other-machine

      git checkout other-machine # go to current branch
      git checkout test5 path/to/abc
      git status # to see the change
    
  5. Pull from remote and replace everything from remote to local

      git fetch origin
      git reset --hard origin/master
    
Top