shellgit remote -v git remote add github https://github.com/chenxiangfang/Main.git git fetch github git merge github/master git push
shellgit fetch github git merge github/master git push git fetch github --all git push origin --all
shell# 全局修改
git config --global user.email "XXX@XXX.com"
git config --global user.name "cainiao"
# 当前仓库修改
git config user.email "XXX@XXX.com"
git config user.name "cainiao"
bashgit config --global credential.helper store
bash# 设置代理
git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
git config --global https.proxy https://proxyUsername:proxyPassword@proxy.server.com:port
# 取消代理
git config --global --unset http.proxy
bash# Switch to the "master" branch:
git checkout master
# Rename it to "main":
git branch -m master main
# Get the latest commits (and branches!) from the remote:
git fetch
# Remove the existing tracking connection with "origin/master":
git branch --unset-upstream
# Create a new tracking connection with the new "origin/main" branch:
git branch -u origin/main
shellgit config --global http.proxy socks5://127.0.0.1:1080 git config --global https.proxy socks5://127.0.0.1:1080 git config --global user.email "565499699@qq.com" git config --global user.name "Xiangfang Chen" git config --global core.autocrlf false git config --global core.filemode false git config --global core.preloadindex true git config --global core.fscache true git config --global branch.autosetuprebase always git config --global core.longpaths true
bash#!/bin/bash
echo "Running git pull on all subdirectories..."
# Find all .git directories recursively and cd to their parent to run git pull
find . -name ".git" -type d | while read gitdir; do
# Extract the parent directory of the .git folder
workdir=$(dirname "$gitdir")
echo ""
echo "========================================"
echo "Pulling latest changes in: $workdir"
echo "========================================"
# Change to the repository directory and pull
(cd "$workdir" && git pull)
done
echo ""
echo "========================================"
echo "Finished pulling all repositories"
echo "========================================"
@echo off echo Running git pull on all subdirectories... REM Loop through all subdirectories recursively for /d /r %%i in (*) do ( REM Check if the directory contains a .git folder if exist "%%i\.git" ( echo. echo ======================================== echo Pulling latest changes in: %%i echo ======================================== cd /d "%%i" git pull ) ) echo. echo ======================================== echo Finished pulling all repositories echo ======================================== pause
bash#!/bin/bash
echo "Running git pull on all subdirectories..."
# Find all .git directories recursively and cd to their parent to run git pull
find . -name ".git" -type d | while read gitdir; do
# Extract the parent directory of the .git folder
workdir=$(dirname "$gitdir")
echo ""
echo "========================================"
echo "Checking repository: $workdir"
echo "========================================"
# Change to the repository directory
(
cd "$workdir"
# Check if there are uncommitted changes
if ! git diff-index --quiet HEAD -- || [ -n "$(git ls-files --exclude-standard --others)" ]; then
echo "Warning: Uncommitted changes detected in $workdir"
echo "Skipping git pull for this repository"
echo "To manually pull, run: cd $workdir && git pull"
else
echo "Pulling latest changes in: $workdir"
git pull
fi
)
done
echo ""
echo "========================================"
echo "Finished checking all repositories"
echo "========================================"
bat@echo off echo Running git pull on all subdirectories... REM Loop through all subdirectories recursively for /d /r %%i in (*) do ( REM Check if the directory contains a .git folder if exist "%%i\.git" ( echo. echo ======================================== echo Checking repository: %%i echo ======================================== cd /d "%%i" REM Check if there are uncommitted changes git diff-index --quiet HEAD -- >nul 2>&1 if errorlevel 1 ( echo Warning: Uncommitted changes detected in %%i echo Skipping git pull for this repository echo To manually pull, run: cd %%i && git pull ) else ( REM Check for untracked files git ls-files --exclude-standard --others | findstr . >nul 2>&1 if errorlevel 1 ( echo Pulling latest changes in: %%i git pull ) else ( echo Warning: Untracked files detected in %%i echo Skipping git pull for this repository echo To manually pull, run: cd %%i && git pull ) ) ) ) echo. echo ======================================== echo Finished checking all repositories echo ======================================== pause
bash#!/bin/bash
echo "Running git pull on all subdirectories (favoring remote changes)..."
# Find all .git directories recursively and cd to their parent to run git pull
find . -name ".git" -type d | while read gitdir; do
# Extract the parent directory of the .git folder
workdir=$(dirname "$gitdir")
echo ""
echo "========================================"
echo "Processing repository: $workdir"
echo "========================================"
# Change to the repository directory
(
cd "$workdir"
# Check if there are any changes to stash
if ! git diff-index --quiet HEAD -- || [ -n "$(git ls-files --exclude-standard --others)" ]; then
echo "Uncommitted changes detected, stashing..."
git stash push -m "Auto stash before git pull ($(date))"
stashed=true
else
stashed=false
fi
# Perform git pull
echo "Pulling latest changes in: $workdir"
git pull
# Restore stashed changes if we stashed any, but favor remote changes on conflict
if [ "$stashed" = true ]; then
echo "Restoring stashed changes (favoring remote changes on conflict)..."
if ! git stash pop; then
echo "Conflict detected. Favoring remote changes and discarding local stash..."
# Abort the merge conflict
git merge --abort 2>/dev/null
git rebase --abort 2>/dev/null
# Drop the stash since we're discarding local changes
git stash drop
echo "Remote changes kept. Local stash discarded."
else
echo "Stashed changes successfully applied"
fi
fi
)
done
echo ""
echo "========================================"
echo "Finished processing all repositories"
echo "========================================"
bat@echo off echo Running git pull on all subdirectories (favoring remote changes)... REM Loop through all subdirectories recursively for /d /r %%i in (*) do ( REM Check if the directory contains a .git folder if exist "%%i\.git" ( echo. echo ======================================== echo Processing repository: %%i echo ======================================== cd /d "%%i" REM Check if there are any changes to stash git diff-index --quiet HEAD -- >nul 2>&1 set stashed=false if errorlevel 1 ( echo Uncommitted changes detected, stashing... git stash push -m "Auto stash before git pull" set stashed=true ) else ( REM Check for untracked files git ls-files --exclude-standard --others | findstr . >nul 2>&1 if errorlevel 0 ( echo Uncommitted changes detected, stashing... git stash push -m "Auto stash before git pull" set stashed=true ) ) REM Perform git pull echo Pulling latest changes in: %%i git pull REM Restore stashed changes if we stashed any, but favor remote changes on conflict if "%stashed%"=="true" ( echo Restoring stashed changes (favoring remote changes on conflict)... git stash pop if errorlevel 1 ( echo Conflict detected. Favoring remote changes and discarding local stash... REM Abort any merge/rebase that might be in progress git merge --abort >nul 2>&1 git rebase --abort >nul 2>&1 REM Drop the stash since we're discarding local changes git stash drop echo Remote changes kept. Local stash discarded. ) else ( echo Stashed changes successfully applied ) ) ) ) echo. echo ======================================== echo Finished processing all repositories echo ======================================== pause
bash#!/bin/bash
echo "Running git pull on all subdirectories (auto-resolving conflicts to favor remote)..."
echo "WARNING: Local changes will be discarded where conflicts occur!"
echo "警告:发生冲突时本地更改将被丢弃!"
# Find all .git directories recursively and cd to their parent to run git pull
find . -name ".git" -type d | while read gitdir; do
# Extract the parent directory of the .git folder
workdir=$(dirname "$gitdir")
echo ""
echo "========================================"
echo "Processing repository: $workdir"
echo "========================================"
# Change to the repository directory
(
cd "$workdir"
# Check if there are any changes to stash
if ! git diff-index --quiet HEAD -- || [ -n "$(git ls-files --exclude-standard --others)" ]; then
echo "Uncommitted changes detected, stashing..."
git stash push -m "Auto stash before git pull ($(date))"
has_stash=1
else
has_stash=0
fi
# Perform git pull
echo "Pulling latest changes in: $workdir"
git pull
# Restore stashed changes if we stashed any, but resolve conflicts in favor of remote
if [ $has_stash -eq 1 ]; then
echo "Restoring stashed changes..."
if ! git stash pop; then
echo "Conflicts detected. Resolving in favor of remote changes..."
# Cancel any ongoing merge/rebase
git merge --abort 2>/dev/null || true
git rebase --abort 2>/dev/null || true
# Reset the index and working tree to match the remote branch
# This discards local changes and keeps remote ones
git reset --hard HEAD
echo "Repository reset to remote state. Local changes discarded."
else
echo "Stashed changes successfully applied"
fi
# Clean up the stash entry
git stash drop 2>/dev/null || true
fi
)
done
echo ""
echo "========================================"
echo "Finished processing all repositories"
echo "========================================"
bat@echo off echo Running git pull on all subdirectories (auto-resolving conflicts to favor remote)... echo WARNING: Local changes will be discarded where conflicts occur! echo "警告:发生冲突时本地更改将被丢弃!" REM Loop through all subdirectories recursively for /d /r %%i in (*) do ( REM Check if the directory contains a .git folder if exist "%%i\.git" ( echo. echo ======================================== echo Processing repository: %%i echo ======================================== cd /d "%%i" REM Check if there are any changes to stash git diff-index --quiet HEAD -- >nul 2>&1 set has_stash=0 if errorlevel 1 ( echo Uncommitted changes detected, stashing... git stash push -m "Auto stash before git pull" set has_stash=1 ) else ( REM Check for untracked files git ls-files --exclude-standard --others | findstr . >nul 2>&1 if errorlevel 0 ( echo Uncommitted changes detected, stashing... git stash push -m "Auto stash before git pull" set has_stash=1 ) ) REM Perform git pull echo Pulling latest changes in: %%i git pull REM Restore stashed changes if we stashed any, but resolve conflicts in favor of remote if "%has_stash%"=="1" ( echo Restoring stashed changes... git stash pop if errorlevel 1 ( echo Conflicts detected. Resolving in favor of remote changes... REM Cancel any ongoing merge/rebase git merge --abort >nul 2>&1 git rebase --abort >nul 2>&1 REM Reset the index and working tree to match the remote branch REM This discards local changes and keeps remote ones git reset --hard HEAD echo Repository reset to remote state. Local changes discarded. ) else ( echo Stashed changes successfully applied ) REM Clean up the stash entry git stash drop >nul 2>&1 ) ) ) echo. echo ======================================== echo Finished processing all repositories echo ======================================== pause
Git command returns fatal error: "detected dubious ownership" fatal: unsafe repository(XXXX is owned by someone else.)
shell# windows:
takeown /r /d y /f <PATH>
# linux:
chown -R username:group <PATH>
# 或者忽略全部文件夹
git config --global --add safe.directory "*"
Filename too long.
shellgit config --global core.longpaths true
本文作者:菜鸟
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 许可协议。转载请注明出处!