## Git Some references : https://1drv.ms/w/s!AndI1JV-h1Q5q3cxK0-DDgsu3kpQ?e=fFEAYX https://blog.csdn.net/weixin_43142797/article/details/105869056 https://miahsuwork.medium.com/%E7%AC%AC%E4%B8%80%E9%80%B1-%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%E8%88%87-git-%E5%9F%BA%E6%9C%AC%E6%8C%87%E4%BB%A4-fa3c4ba286a2 https://miahsuwork.medium.com/%E7%AC%AC%E4%BA%8C%E9%80%B1-git-%E6%9C%AC%E5%9C%B0%E7%AB%AF%E8%88%87%E9%81%A0%E7%AB%AF%E6%93%8D%E4%BD%9C-github-78eec4537179 Other references : https://medium.com/@flyotlin/%E6%96%B0%E6%89%8B%E4%B9%9F%E8%83%BD%E6%87%82%E7%9A%84git%E6%95%99%E5%AD%B8-c5dc0639dd9 https://stackoverflow.com/questions/12940626/github-error-message-permission-denied-publickey https://blog.csdn.net/ppt_no1/article/details/126612236 ### Pre-setting ```linux= sudo apt-get install git git --version //Setup your account git config --global user.name "" git config --global user.email ``` ```linux= git config --list ``` ### Using * Clone a single branch ```linux= git clone --single-branch --branch=<branch name> <url> ``` * See the status ```linux= git status git status --short git remote -v git log git diff ``` * Modify the remote repository ```linux= ##Edit the url git remote set-url origin url ##Add a new url git remote add myorigin url #Delete git remote rm name git remote remove name ``` * First create the repossitory on your github. * Then follow the commands below to upload your code. ```linux= git init git add <file name> git add . //Add all the files in currnet folder. git commit -m "" //Put the describtion message. git branch -M main git remote add origin <url> git push -u origin main //-u can specitfy the upstream ``` * Modify in different branch ```linux= git checkout -b 你的分支名 git checkout 已存在的分支名 ``` ### SSH problem ```ubuntu= ubuntu@ubuntu:~$ git push -u origin main git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. ``` ```linux= ubuntu@ubuntu:~$ ssh -T git@github.com git@github.com: Permission denied (publickey). ``` :::success **Solution 1** ```linux= ssh-keygen -t rsa -C "jimmy20152811@gmail.com" cd .ssh nano id_rsa.pub ``` * Copy the contents in .pub file. * Add a new ssh key in github and paste the contents in it. ```linux ubuntu@ubuntu:~$ ssh -T git@github.com Hi jimmy20152811! You've successfully authenticated, but GitHub does not provide shell access. ``` ::: :::success **Solution 2** * Use the https link to push instead of the ssh link. * [Reference](https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls) * But is has problem like below: ```linux ubuntu@ubuntu:~$ git remote add ori https://github.com/jimmy20152811/Free5GC_3.3_test ubuntu@ubuntu:~$ git remote -v ori https://github.com/jimmy20152811/Free5GC_3.3_test (fetch) ori https://github.com/jimmy20152811/Free5GC_3.3_test (push) origin git@github.com:jimmy20152811/Free5GC_3.3_test.git (fetch) origin git@github.com:jimmy20152811/Free5GC_3.3_test.git (push) ubuntu@ubuntu:~$ git push -u ori main Username for 'https://github.com': Jimmy Password for 'https://Jimmy@github.com': remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/jimmy20152811/Free5GC_3.3_test/' ubuntu@ubuntu:~$ git push -u ori main Username for 'https://github.com': Jimmy Password for 'https://Jimmy@github.com': remote: Support for password authentication was removed on August 13, 2021. remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication. fatal: Authentication failed for 'https://github.com/jimmy20152811/Free5GC_3.3_test/' ``` ::: ### SSH problem 2 :::danger * When ssh problem 1 is happended but **ssh -T git@github.com** is successful. * All command need sudo to input but push command will get error for permission. * When changing the SSH key on PC is not useful. * After PC IP binding on NIC is changed. * **After sudo cp -R this folder** ::: :::info * The process. ![image](https://hackmd.io/_uploads/SJ5TrKtcR.png) ![image](https://hackmd.io/_uploads/rJSABttqC.png) ![image](https://hackmd.io/_uploads/ry4yIYFqR.png) ::: :::success ``` git config --global --add safe.directory /home/jimmy/free5gc_backup/free5gc_PCF_v0.1 sudo chown -R $USER:$USER /home/jimmy/free5gc_backup/free5gc_PCF_v0.1 git push -u origin v3.3_AUSF-NSSF-PCF_v0.1 ``` ![image](https://hackmd.io/_uploads/HJ5pIYKc0.png) * Second error. ![image](https://hackmd.io/_uploads/BkgJDYF50.png) ![image](https://hackmd.io/_uploads/SJ1fPtK50.png) ::: ### Submodule problem * The error message which kept popping up in vscode before was also due to this problem(modify the files from clone derectly), so there were some of modification tags in folder list like below. ![image](https://hackmd.io/_uploads/SklpA4uDT.png) * Normally it would look like this. ![image](https://hackmd.io/_uploads/HJYlgrdDa.png) ```linux Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) (commit or discard the untracked or modified content in submodules) modified: free5gc_v3.3_01 (modified content, untracked content) ``` ![image](https://hackmd.io/_uploads/rkIs-JQw6.png) ```linux ubuntu@ubuntu:~/free5gc$ git status Not currently on any branch. Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) (commit or discard the untracked or modified content in submodules) modified: Makefile modified: NFs/amf (modified content) modified: NFs/nrf (modified content) modified: config/amfcfg.yaml modified: config/smfcfg.yaml modified: config/upfcfg.yaml modified: run.sh no changes added to commit (use "git add" and/or "git commit -a") ``` :::success #### Solution 1 * Because I didnt clear the association between the file I cloned and the original repository. ```linux= rm -rf .git ``` * BUT after reuploading successfully, I still didnt know why .yaml in config folder disappered, maybe due to the messy process of dealing this problem. * Normal ![image](https://hackmd.io/_uploads/rJgNr-uDp.png) * Abnormal ![image](https://hackmd.io/_uploads/BkfBSb_vT.png) * Other files are not changed because the newest modification records still exists. ::: :::success #### Solution 2 * Use "Fork" to make a clean copy of the file. ![image](https://hackmd.io/_uploads/B1g89l_Pp.png) ![image](https://hackmd.io/_uploads/BknIqlOPa.png) ![image](https://hackmd.io/_uploads/ryCuqxuwa.png) ::: ### Secret problem ![image](https://hackmd.io/_uploads/SkgjcaRAp.png) ![image](https://hackmd.io/_uploads/HyMhq6RAa.png) :::success #### Solution 1 * Click each link to unblock every blocked key. ![image](https://hackmd.io/_uploads/H1-lsaA0a.png) ::: :::success #### Solution 2 [Ref](https://blog.csdn.net/crisschan/article/details/136866137) * Close the key checking in setting, and push again. * After push, you should turn it on again. ![image](https://hackmd.io/_uploads/SJx7opCRT.png) ![image](https://hackmd.io/_uploads/BJJEoaC0p.png) :::