Git common errors and Solutions

Posted by s.prema@yahoo.com on Thu, 10 Feb 2022 20:24:22 +0100

Git errors and Solutions

2021/12/23

  • Step 1: set up Git warehouse

    git init (only used once when building a warehouse)

    cd to your local project root directory and execute git command. This command will create one in the current directory Git folder.

  • Step 2: add all files of the project to the warehouse

    git add .

    This command will add all files in the current path to the list of files to be uploaded.

    If you want to add a specific file, just put it Change to a specific file name

  • Step 3: commit the add file to the warehouse

    git commit -m "comment statement"

  • reference resources: git upload code steps - Jianshu (jianshu.com)

2021/12/24

1. You are not currently on a branch

git push

peng@ubuntu:~/git/ytc-nordic-sdk$ git push
fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD)
state now, use

    git push origin HEAD:<name-of-remote-branch>

It is not currently on a branch, so it cannot be pull ed or push ed

terms of settlement

Check with git branch and find:

 * (HEAD detached from a6d7be9)  
  kang 
  master
  test
  tmp

We are currently on (HEAD detached from a6d7be9)

So we did it

git branch temp a6d7be9 // Create temp branch based on snapshot a6d7be9
git checkout master		// Switch to the master branch
git merge temp			// Merge temp branch into master branch

Then you can submit with git push

reference resources: (30 messages) You are not currently on a branch_ Tyrant CSDN blog

1.[Git-error]Your local changes to the following files would be overwritten by checkout

Question:

When using git checkout command to switch branches, the switch fails because there are untracked files in the current branch.

error: Your local changes to the following files would be overwritten by checkout:
        main.c
Please commit your changes or stash them before you switch branches.
Aborting

Solution

There are two options: A save modification; B waiver of modification

Select A: it is very important to change the contents of the untracked file. Save the changes

Select A: it is very important to change the contents of the untracked file. Save the changes

Method ①: save to temporary storage area

git add .
git stash 
// Use when removing 
git stash pop

Method ②: initiate a commit and save it to the submission history

git add .
git commit -m "commit message"

Select B: the content change of the untracked file is not important, and the modification is abandoned

Two methods: ① clear and modify; ② Force branch switching

Method ①: clear untracked files [recommended practice]

git clean -n         //This is the clear file preview
git clean -f         //Force file cleanup

Method ②: force branch switching

git checkout -f <branch>        // < Branch > is the branch name to be switched to. Note that "< >"

reference resources: (30 messages) [git error] Your local changes to the following files would be overwritten by checkout_dandelionela blog - CSDN blog

3. Local recovery after wrong operation

Git reflog: (Reference logs) is a very important command for recovering local error operations, so I'll sort it out here.

4. Error:

peng@ubuntu:~/git/ytc-nordic-sdk$ git push
warning: redirecting to http://192.168.130.13/device/ytc-nordic-sdk.git/
Everything up-to-date

**Error reason: * * Git recognizes that the code has not been changed

terms of settlement:

Add an arbitrary line of comment to the code, make changes, and then submit it again

5. Error:

[the external chain picture transfer fails, and the source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-O3pc7WIw-1644470536718)(D: \ mine safety technology \ Picture_data \ error 5.png)]

**Cause of problem: * * virtual machine network connection failed

**Solution: * * check the network and configure the network

[the external chain picture transfer fails, and the source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-LxpAJrmi-1644470536719)(D: \ mine safety technology \ Picture_data \ error 5_1.png)]

problem

View your user name and email address

$ git config user.name

$ git config user.email

Modify your user name and email address:

$ git config --global user.name "xxx"

$ git config --global user.email "xxx"

When solving git push, you need to enter the user name and password every time

1. Enter in the current project directory

git config credential.helper store

There is no – global here, which means that it is only effective for this warehouse. It is recommended not to add – global in the future. Just let the code configuration be stored in the warehouse as a unit, which is set to be globally inflexible

2. Open The config file in git folder will find two more lines

3.git push to the remote warehouse, enter the user name and password according to the prompt, and pay attention to entering the correct (GitHub user name and password)

4. If you run git push again, you don't need to enter the user name and password, because there is a file git credentials in the user's home directory folder, which is used to store the user name and password

5. If you want to delete the user name and password of the project, enter the following command

git credential-manager uninstall

In this way, you need to enter the user name and password every time git push.

The above statement is generally used to solve the 403 error in push, pull or clone. Unbind it first, and then bind the user name and password.

reference resources: https://blog.csdn.net/xiecheng1995/article/details/107226818?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none -task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1. no_ search_ link&depth_ 1-utm_ source=distribute. pc_ relevant_ t0. none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7Edefault-1. no_ search_ link&utm_ relevant_ index=1

problem

git branch -a can't see the remote branch

terms of settlement:

Update the local and remote tracking branches through git fetch to keep consistent with the remote branches

Then use git branch -a again to view the remote branch

problem

To http://192.168.130.13/device/zuangan.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'http://192.168.130.13/device/zuangan.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

terms of settlement

git pull --rebase
git push
unterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

terms of settlement

git pull --rebase
git push

Topics: git github