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/第一週-版本控制與-git-基本指令-fa3c4ba286a2
https://miahsuwork.medium.com/第二週-git-本地端與遠端操作-github-78eec4537179

Other references :
https://medium.com/@flyotlin/新手也能懂的git教學-c5dc0639dd9
https://stackoverflow.com/questions/12940626/github-error-message-permission-denied-publickey
https://blog.csdn.net/ppt_no1/article/details/126612236

Pre-setting

sudo apt-get install git git --version //Setup your account git config --global user.name "" git config --global user.email
git config --list

Using

  • Clone a single branch
git clone --single-branch --branch=<branch name> <url>
  • See the status
git status git status --short git remote -v git log git diff
  • Modify the remote repository
##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.
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
git checkout -b 你的分支名 git checkout 已存在的分支名

SSH problem

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.
ubuntu@ubuntu:~$ ssh -T git@github.com git@github.com: Permission denied (publickey).

Solution 1

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.
ubuntu@ubuntu:~$ ssh -T git@github.com
Hi jimmy20152811! You've successfully authenticated, but GitHub does not provide shell access.

Solution 2

  • Use the https link to push instead of the ssh link.
  • Reference
  • But is has problem like below:
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

  • 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
  • The process.
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →
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 Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

  • Second error.
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

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 Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →
  • Normally it would look like this.
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →
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 Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

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")

Solution 1

  • Because I didnt clear the association between the file I cloned and the original repository.
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
    • Abnormal
      image
  • Other files are not changed because the newest modification records still exists.

Solution 2

  • Use "Fork" to make a clean copy of the file.
    image
    image
    image

Secret problem

image
image

Solution 1

  • Click each link to unblock every blocked key.
    image

Solution 2

Ref

  • Close the key checking in setting, and push again.
  • After push, you should turn it on again.
    image
    image