diff --git a/up b/up index 6ba5ebd..329a919 100755 --- a/up +++ b/up @@ -37,12 +37,26 @@ while IFS= read -r repo_path || [[ -n "$repo_path" ]]; do continue fi + # Check if 'origin' remote exists + if ! git remote | grep -q '^origin$'; then + echo "Remote 'origin' not found. Attempting to set it up..." + # Try to guess the remote URL based on the directory name + repo_name=$(basename "$repo_path") + remote_url="https://git.sij.ai/sij/$repo_name.git" + git remote add origin "$remote_url" + echo "Added remote 'origin' with URL: $remote_url" + fi + # Get the current branch current_branch=$(git rev-parse --abbrev-ref HEAD) # Pull the latest changes from the repository echo "Pulling from $current_branch branch..." - git pull origin "$current_branch" + if ! git pull origin "$current_branch"; then + echo "Failed to pull from origin. The remote branch might not exist or there might be conflicts." + echo "Skipping further operations for this repository." + continue + fi # Add changes to the Git index (staging area) echo "Adding all changes..." @@ -58,7 +72,11 @@ while IFS= read -r repo_path || [[ -n "$repo_path" ]]; do # Push changes to the remote repository echo "Pushing all changes..." - git push origin "$current_branch" + if ! git push origin "$current_branch"; then + echo "Failed to push changes. The remote branch might not exist." + echo "Creating remote branch and pushing..." + git push -u origin "$current_branch" + fi fi echo "Update complete for $repo_path!"