- Select SSH Private key in sourcetree
- Tools -> Options -> SSH Client Configuration
- Add SSH key in Putty Pageant
- Past public key in Bitbucket setting.
Category Archives: Git
Checkout remote branch
1 2 3 4 5 |
git fetch origin git branch -v -a git checkout -b test origin/test |
Reference:
https://stackoverflow.com/questions/1783405/how-do-i-check-out-a-remote-git-branch
Git pull show all files are modified and with a lot conflicts
- Change line ending config
1git config core.autocrlf true - Change file mode:
1234567891011// Check current statusgit config core.filemode// Current foldergit config core.filemode false// System levelgit config --system core.filemode false// Globalgit config --global core.filemode false - Clear cache
1git rm --cached -r .
Reference:
- elharony commented on 7 Dec 2018
https://github.com/microsoft/WSL/issues/184 - https://github.com/microsoft/WSL/issues/2900
Add existing folder in repo and track remote branch
Github solution
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$ git init $ git add . $ git commit -m "First commit" $ git remote add origin [remote repository URL] $ git remote -v git branch --set-upstream-to=origin/master master $ git push origin master |
Reference:
Change Remote URL of Git Repo
Track remote branch (RSA Key for bitbucket) with public key
把目前使用中,而且沒有git的資料夾track remote branch
- 連線的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
- ssh-keygen
- Press the Enter or Return key to accept the default location. (Or leave it empty)
- Enter and re-enter a passphrase when prompted.
- ls ~/.ssh id_rsa id_rsa.pub
- eval
ssh-agent
1eval `ssh-agent` - ssh-add ~/.ssh/<private_key_file>
- cat ~/.ssh/id_rsa.pub
- Paste public key to bitbucket
- Git commands to track remote branch
- git init
- git add .
- git commit -m ‘Init git’ (Current branch is master)
- git remote add origin [email protected]:/opt/git/project.gitReference
or
1git branch --set-upstream-to=origin/master master
- git fetch
- git branch -u origin/master
Fix “detached HEAD” error
https://gitbook.tw/chapters/faq/detached-head.html
Fix “refusing to merge unrelated histories” error:
- Force pull
1git pull origin master --allow-unrelated-histories
- Fix conflicts maybe. Uploading files with conflicts by FTP could be the fastest solution.
- git add .
- commit
- Done
Note: 執行完上方command後,兩方client有不同步或是持續出現conflict的問題,重覆修正幾次之後就好了。原因不明。 Reference:
Git related commands
Common
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
git status git add <file> git add . git commit -m 'commit content' //Clone a repo into current folder git clone git@bitbucket.org:partners/tw.git . git push git pull //Discard unstaged changes git checkout -- <file> git checkout -- . //Check difference between files git diff hello.txt //Merge from branch dev or remote branch origin/testing git merge dev git merge origin/testing //Check difference between last 2 git log -p -2 //Checkout a remote branch git checkout --track origin/dev //Push to remote branch git push -u origin dev //Set track of a local branch git branch -u origin/dev //Stop tracking a file git rm --cached worker.log git rm -r --cached path_to_your_folder/ // Show all remote URL git remote -v // Show files in a commit //https://stackoverflow.com/questions/424071/how-to-list-all-the-files-in-a-commit git show --pretty="" --name-only bd61ad98 |
push.default warning
1 |
git config --global push.default simple |
Ignored files still display in git status?
1 |
git rm --cached <file> |
- Warning! If other users pull this commit, this file will be removed, so remember notify others to backup their files if they need it. e.g. index.php for Codeigniter
- https://stackoverflow.com/questions/1818895/keep-ignored-files-out-of-git-status
Set User Info
1 2 |
git config --global user.name "xxx"<code> |
Reference:
- Official Doc
https://git-scm.com/book/zh-tw/v1/Git-%E5%9F%BA%E7%A4%8E-%E5%8F%96%E5%BE%97Git%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%E5%80%89%E5%BA%AB - https://www.git-tower.com/learn/git/faq/track-remote-upstream-branch
- https://git-scm.com/book/zh-tw/v1/Git-%E5%9F%BA%E7%A4%8E-%E6%AA%A2%E8%A6%96%E6%8F%90%E4%BA%A4%E7%9A%84%E6%AD%B7%E5%8F%B2%E8%A8%98%E9%8C%84
Change Remote URL
1 |
git remote set-url origin https://github.com/USERNAME/OTHERREPOSITORY.git |
Reference: https://gist.github.com/fokayx/255b228ded2bca1c4f60
Change bitbucket password in sourcetree
Process:
The only thing that worked for me was navigating to C:\Users\USERNAME\AppData\Local\Atlassian\SourceTree and removing the passwd file.
- If you choose to remember password,, you need to remove password file:
https://community.atlassian.com/t5/Sourcetree-questions/How-to-update-HTTP-S-credentials-in-sourcetree/qaq-p/297564
Delete a commit or merge before push
Before push:
1 |
git reset --hard f3a5a11b016d7efbcdecfa99bdfadb0ad9592f94 |
Reference:
To use SSH in SourceTree
- SourceTree accept putty format key file only
- If your SSH is generated by Git bash, you have to convert it to putty format (.ppk)
open puttygen.exe -> load private key -> save private key - Config SSH in Sourcetree:
Tools -> Options -> SSH Key
Reference: