Featured image of post Record of Git Usage Issues

Record of Git Usage Issues

Table of contents

The problem of garbled Chinese display in git log under Ubuntu while foreign languages are displayed normally

Description:

The Chinese is displayed as angle brackets <E4><B8><B4><E6><97><B6><E4><BF><9D><E5><AD><98>

Solution:

1
2
3
git config --global i18n.commitencoding utf-8
git config --global i18n.logoutputencoding gbk
export LESSCHARSET=utf-8
SHELL

Similar problems may also occur when using git status, but the causes are different. The following command can be used to solve it

1
git config --global core.quotepath false
SHELL

Multiple uncommitted changes still exist on another system after committing when developing based on mounted files across systems

Description:

When local development is performed between multiple systems and the mounted directory is used for coding and commit separation, it often occurs that a commit is made on one end, while the other end, such as VS Code, prompts multiple unadded changes. This is often due to the filemode difference between different systems.

Solution:

1
git config --add core.filemode false
SHELL

Modify submodule

Modify the url attribute of the corresponding module in the.gitmodules file;

Use the git submodule sync command to update the new URL to the file.git/config;

Then use the command to initialize the submodule: git submodule init

Finally, use the command to update the submodule: git submodule update

Reference: Git Modify. The URL of the Submodule File Takes Effect

Error when pulling submodules from non-current user or group repositories using gitea action

Reference Key Configuration for gitea action checkout

It is necessary to configure the key pair of the action properly. Configure the public key in the submodule one by one and the private key in the repository where the action is located and pass it to the action. After correctly configuring the key in the action, the pull can be performed normally.

Set different upstreams for different branches in git

one repo with multi upstream
    Configure Different Remote Repositories for Different Branches

Logical View

RmeyproepoBpprruaibnvlcaihtceRggeiimtto.htmueybd.Locomocamaitni.ocnom(((IPPnuucbrrlpeiomcseenr)tealleawsoersk))

Implementation Process

  1. Create a New Repository

If based on an existing repository, skip directly to step 2

1
2
3
4
5
# Create a new repository
$: mkdir myrepo; cd myrepo

# Initialize the repository
$: git init
SHELL
  1. Add Remote Repository Sources
1
2
3
# github and mydomain are the aliases of the added sources, called <source name>
$: git remote add github https://github.com/foo/bar.git
$: git remote add mydomain https://git.mydomain.com/foo/bar.git
SHELL

Display Remote Repositories:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Display all remote repositories
$: git remote -v

# Display the information of a certain remote repository
$: git remote show <source name>

# Delete a remote repository
$: git remote rm <source name>

# Modify the alias of a remote repository
$: git remote rename <old name> <new name>
SHELL
  1. Create a Blank Branch
1
2
# Create a blank branch dev
$: git checkout --orphan public
SHELL

If it is based on an existing branch, it needs to be emptied

1
2
# Note there is a period at the end
$: git rm -rf.
SHELL
  1. Pull Branches and Associate Local Branches with Remote Branches

Under the created blank branch, pull the code of the specified branch of the remote repository.

1
2
3
4
5
6
7
8
# github alias, master is the name of the github remote branch to reference
$: git pull github master

# Associate the remote branch
$: git branch --set-upstream-to=github/master public

# Or
$: git branch -u github/master public
SHELL

At this point, we have created a local branch and associated it with a remote branch.

Similarly, to create other branches, just repeat steps 3 and 4.

For example, to create the private branch and associate it with the private branch of the remote repository mydomain, the steps are as follows:

1
2
3
$: git checkout --orphan private
$: git pull mydomain private
$: git branch -u github/private private
SHELL
  1. Push Local Branches

Because the local branch has been associated with the remote branch, only git push is needed when pushing.

If the remote branch has not been associated, then:

1
$: git push <source name> <branch name>
SHELL

请在评论前阅读我们的评论政策


内容是由智能博客生成器生产 powered by ChatGGPTT
Built with Hugo
Theme Stacked designed by Jimmy, modified by Jacob