Skip to content

Instantly share code, notes, and snippets.

@Juanpa0128j
Created November 21, 2024 14:30
Show Gist options
  • Select an option

  • Save Juanpa0128j/f28167dd805dcddbc2a6c20ef6a8640b to your computer and use it in GitHub Desktop.

Select an option

Save Juanpa0128j/f28167dd805dcddbc2a6c20ef6a8640b to your computer and use it in GitHub Desktop.
Performs env update, add, comit and push in a single call
function autopush() {
# Usage: autopush "commit message" branch_name path_to_your_repo
# Check if commit message and branch name are provided
if [ "$#" -ne 3 ]; then
echo "Usage: autopush \"commit message\" branch_name path_to_your_repo"
else
# Set variables from arguments
COMMIT_MSG="$1"
BRANCH_NAME="$2"
REPO_PATH="$3"
YAML_FILE="environment.yml"
# Step 1: Export the Conda environment to a YAML file
echo "Exporting Conda environment..."
conda env export | sed '/^prefix: /d' > "$REPO_PATH/$YAML_FILE"
# Step 2: Navigate to the repository and commit the changes
cd "$REPO_PATH" || exit
git add .
git commit -m "$COMMIT_MSG"
# Step 3: Push the changes to the specified branch
echo "Pushing changes to $BRANCH_NAME..."
git push origin "$BRANCH_NAME"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment