Category Archives: Git

Git pull show all files are modified and with a lot conflicts

  1. Change line ending config
  2. Change file mode:
  3. Clear cache

Reference:

  1. elharony commented on 7 Dec 2018
    https://github.com/microsoft/WSL/issues/184
  2. https://github.com/microsoft/WSL/issues/2900

Add existing folder in repo and track remote branch

Github solution

Reference:

  1. https://docs.github.com/en/github/importing-your-projects-to-github/adding-an-existing-project-to-github-using-the-command-line
  2. https://docs.github.com/en/github/using-git/adding-a-remote

Track remote branch (RSA)

把目前使用中,而且沒有git的資料夾track remote branch

  1. 連線的PC or server要有SSH Key, 並且把Public key的內容貼到Bitbucket的Repo設定裡
    Step by step tutorial: https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html

    1. ssh-keygen
    2. Press the Enter or Return key to accept the default location.
      (Or leave it empty)
    3. Enter and re-enter a passphrase when prompted.
    4. ls ~/.ssh
      id_rsa id_rsa.pub
    5. eval ssh-agent
    6. ssh-add ~/.ssh/<private_key_file>
    7. cat ~/.ssh/id_rsa.pub
    8. Paste public key to bitbucket
  2. Git commands to track remote branch
    1. git init
    2. git add .
    3. git commit -m ‘Init git’
      (Current branch is master)
    4. git remote add origin git@gitserver:/opt/git/project.gitReference
      or
    5. git fetch
    6. git branch -u origin/master

Fix “detached HEAD” error

https://gitbook.tw/chapters/faq/detached-head.html

Fix “refusing to merge unrelated histories” error:

  1. Force pull
  2. Fix conflicts maybe.
    Uploading files with conflicts by FTP could be the fastest solution.
  3. git add .
  4. commit
  5. Done

Note: 執行完上方command後,兩方client有不同步或是持續出現conflict的問題,重覆修正幾次之後就好了。原因不明。

Reference:

  1. https://stackoverflow.com/questions/24916708/track-existing-folder-from-remote-git-repo
  2. Track Remote Branch https://stackoverflow.com/questions/520650/make-an-existing-git-branch-track-a-remote-branch
  3. Common commands related to remote https://backlog.com/git-tutorial/tw/reference/remote.html

Git related commands

Common

push.default warning

Ignored files still display in git status?

Set User Info

Reference:

Clone a repository from GitLab with SSH

  1. Create a SSH key (Git bash is recommended):
    https://docs.gitlab.com/ee/ssh/
  2. Login Gitlab and paste SSH key in account page
    https://hk.saowen.com/a/a94e3743e7b0591aca8b3bd6361ee64c6c7ffae1863c205f0f602f77307537d6
  3. Execute clone command:

    https://git-scm.com/book/zh-tw/v2/Git-%E5%9F%BA%E7%A4%8E-%E5%8F%96%E5%BE%97%E4%B8%80%E5%80%8B-Git-%E5%80%89%E5%84%B2
  4. Then you can create a new repo in Source Tree or Github Desktop

Reference:

  1. https://yehchitsai.gitbooks.io/linux-usage/content/use_gitlab.html