Skip to main content

5 posts tagged with "git"

View All Tags

Date created: 2024-10-01

Use Github actions to deploy to a server through SSH

  • Add the following secrets to your Github repo

    • SSH_HOST
    • SSH_USERNAME
    • SSH_PRIVATE_KEY
  • Add the following job to your github actions workflow, and modify the script that is being run on the server.

jobs:
deploy:
name: Deploy
needs: build_test
runs-on: ubuntu-latest
steps:
- name: Deploy using ssh
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
port: 22
script: |
ssh-keyscan -H github.com >> ~/.ssh/known_hosts
cd <project/directory/on/server>
git pull origin master
git status
npm install
npm run build

Date created: 2024-09-26

Typical usage

Named stash (stash with message)

$ git stash -m 'stash message'

Stash including untracked files

$ git stash -u -m 'stash message'

List stashes, and take note of the index of the one you need

$ git stash list

Apply unstashes a stash, but keeps the stash

$ git stash apply <index-of-stash-to-apply>

Pop unstashes a stash, and removes it from the list of stashes

$ git stash pop <index-of-stash-to-apply>

Date created: 2024-09-23

Resources and links

https://www.reddit.com/r/AskProgramming/comments/wai4i4/comment/ii3jiyk/

Go wild here

#!/bin/bash

set -e

if [ $# -eq 0 ]; then
cat <<EOF
usage: gitlazy [log message]

This script pulls the latest source, adds all files, commits and pushes
back to master. You can run as per the example below

$ gitlazy updated modules for user management
$ On branch master
$ Your branch is up to date with 'origin/master'.
$ Everything up-to-date

EOF
exit 1
fi

git pull
git add -A
git commit -m "$@"
git push

Date created: 2024-10-01

Switch current working directory to Git repository root

Note: since this spawns another terminal, it can't be used as a script file, and should instead be put into the .bashrc directly.

#!/bin/bash

# Ensure the script is being run from the root of a Git repository
GIT_ROOT=$(git rev-parse --show-toplevel)
if [ $? -ne 0 ]; then
echo "Error: Not inside a Git repository."
exit 1
fi

# Change to the Git root directory
cd "$GIT_ROOT" || exit 1
echo "Navigating to Git root: $GIT_ROOT"