git init -b main
git add .
git commit -m 'Initial commit'
git remote add origin [email protected]:youruser/yourrepo.git
git push -u origin main
git config --global pull.rebase true
FILE=.hooks/go-vet.sh
chmod +x $FILE
git add $FILE
mkdir directory
touch directory/.gitkeep
git add directory
git commit -m "Adding directory"
git push origin main
OLD_NAME=oldbranchname
NEW_NAME=waybettername
git branch -m $OLD_NAME $NEW_NAME
Resource: https://www.ionos.com/digitalguide/websites/web-development/renaming-a-git-branch/
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
git checkout develop
git merge main
At this point, if there are any merge conflicts, you can resolve them.
git checkout main
git merge develop
git push origin main
Resource: https://stackoverflow.com/questions/14168677/merge-development-branch-with-master
git checkout main
git checkout source_branch <paths>...
For example, this will get the .gitignore from develop:
git checkout develop .gitignore
Resource: https://jasonrudolph.com/blog/2009/02/25/git-tip-how-to-merge-specific-files-from-another-branch/
When you’re introducing changes to another open source project, sometimes your fork gets out of sync with the original project. To fix this, do the following:
Fetch the latest changes from the upstream repository:
Check out the branch you want to synchronize (e.g., main):
Reset your local branch to match the upstream branch exactly:
git reset --hard upstream/main
Force-push the reset branch to your fork on GitHub:
Note: This will overwrite your branch in the forked repository to exactly match the branch of the original repository, discarding all the commits that are unique to your forked branch.
In the event that you get this error:
fatal: 'upstream' does not appear to be a git repository
Check if the upstream for the original project is set:
If it isn’t, get the url for the git repo and run it with this command:
git remote add upstream https://github.com/<original project>
For example, if I was working on my copy of the xssValidator project, and wanted to add the upstream for the original:
git remote add upstream https://github.com/nVisium/xssValidator
Pushed too soon or by accident? Let’s fix that. Non-rebase approach:
git reset --hard HEAD^
git push origin +master
Rebase approach:
git rebase -i HEAD~2
# Delete the commit (should be the second line in the text file)
git push origin +$BRANCH_NAME
Note: + is used to force a push to only one branch.
Resources: https://git-scm.com/docs/git-push
git checkout <branch>git rebase -i <ref #>git commit --amend - change the commit message to what you wantgit rebase --continuegit push -u origin <name of branch>git checkout <branch to merge from> <file name>
git checkout $BRANCH_TO_OVERWRITE
# Rebase all changes on $BRANCH_TO_OVERWRITE
# onto the tip of main
git rebase origin/main
git add $FILE
git commit --amend
git stash
git checkout $ANOTHER_BRANCH
# Do stuff on this branch
git checkout $FIRST_BRANCH
git pop
git stash save --keep-index
git stash drop
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch ${FILENAME}"
git push origin --force --all
Find the commit before (chronologically) the first commit that you want to change:
git rebase -i <SHA hash of the commit before the one you want to change>
Change the lines for the commits you want to modify by
changing them from pick to edit.
Save the file once you’re done.
Change the commit to the author you want to be reflected like so:
Once you’ve changed the author for the commit, continue
on through the rebase using git rebase --continue until
all commits have been resolved.
You may need to deal with some errors that come up,
so be sure to fix those, and then git add the file that
you’ve had to resolve before using git rebase --continue.
Finish with git push --force
Resource: https://stackoverflow.com/questions/3042437/change-commit-author-at-one-specific-commit
git commit --amend --author="Philip J Fry <[email protected]>"
Resource: https://makandracards.com/makandra/1717-git-change-author-of-a-commit
Resource: https://stackoverflow.com/questions/927358/how-to-undo-the-last-commits-in-git
git submodule add <git repo> <destination path - optional>
This should generate .gitmodules file and
the folder of the repo you intended to submodule.
The first time you check out a repo:
git submodule update --init --recursive
If you’ve already checked out a repo:
git submodule update --recursive --remote
Resource: https://stackoverflow.com/questions/1030169/pull-latest-changes-for-all-git-submodules
git clone --recurse-submodules <repo with submodules>
git rm -r the_submodule
rm -rf .git/modules/the_submodule
git config -f .git/config --remove-section submodule.the_submodule 2> /dev/null
Resource: https://stackoverflow.com/questions/1260748/how-do-i-remove-a-submodule
This is very useful if you want to use SSH for the vast majority of the time and a Personal Access Token for certain cases.
git submodule init
# Get submodules
submodules=($(git config --file .gitmodules --get-regexp url \
| awk -F ' ' '{print $2}'))
# Remove empty cells from submodules array
for i in "${!submodules[@]}" ; do submodules[$i]="${submodules[$i]:-other}"; done
# Replace URLs with HTTPs using the input Personal Access Token
for submodule in "${submodules[@]}"; do
# Get owner
owner=$(echo "$submodule" | awk -F '/' '{print $1}' | awk -F ':' '{print $2}')
# Get full repo name - for example, if you have ansible-role,
# $full_repo_name will reflect that
full_repo_name=$(echo "$submodule" \
| awk -F '/' '{print $2}' | awk -F '.' '{print $1}')
# Get only repo name - for example, if you have ansible-role,
# $repo_name will be assigned roll and omit ansible-
repo_name=$(echo "$full_repo_name" | awk -F '-' '{print $2}')
# Change the values in ~.git./config
git config submodule.$repo_name.url https://[email protected]/$owner/$full_repo_name.git
# Change the values in ~/.gitmodules
git submodule set-url -- roles/$repo_name https://[email protected]/$owner/$full_repo_name.git
done
# Update local submodules with the changes we made
git submodule update --recursive --remote
Resource: https://www.damirscorner.com/blog/posts/20210423-ChangingUrlsOfGitSubmodules.html
git commit --amend --no-edit
git commit --amend -m "new commit message goes here"
You can also omit the -m and the message following it
if you want to edit the commit in a text editor.
Alternatively:
git push -f origin $BRANCH
Resource: https://medium.com/@igor_marques/git-basics-adding-more-changes-to-your-last-commit-1629344cb9a8
git clone git://github.com/SomeUser/SomeRepo.git
Resource: https://superuser.com/questions/557903/clone-github-repository-without-account
This is helpful when you run something like Gitleaks, and want to be able to look at specific commits. Unfortunately, the UI does not seem to provide a place to do this.
https://gitlab.com/projectname/reponame/commit/commitid
This can be used if you need to automatically clone into a private gitlab repo as part of a CI/CD pipeline. Be sure to set an expiration date if you can get away with it for security.
Use it to clone the repo:
git clone https://<gitlab+deploy-token-number>:<token_password>@gitlab.com/group/repo.git
Resource: https://docs.gitlab.com/ee/user/project/deploy_tokens/#creating-a-deploy-token
ssh-keygen -t ed25519 -C "<your email>" -f ~/.ssh/personal_github
Add a section to ~/.ssh/config for the key you just created:
Host github.com-l50
HostName github.com
User git
IdentityFile ~/.ssh/personal_github
IdentitiesOnly yes
If you’re running OSX, run this command to add your new key to your keychain:
ssh-add ~/.ssh/personal_github
If you’re running on Linux, run this command to add your new key to your keychain:
ssh-add -k ~/.ssh/personal_github
Finally, add your public key to github.
Resources:
Generate an ssh key using the information under CREATE SSH KEY found on this page
echo "Your public key:"
cat ~/.ssh/id_rsa.pub
echo
echo "Your ssh key fingerprint is:"
ssh-keygen -lf ~/.ssh/id_rsa | awk '{ print $2 }'
If you create a release and have to make some changes and then re-release, here’s what you need to do:
git tag -f -a <tagname> ## i.e. v1.0.0
git push -f --tags
for tag in tag1 tag2 tag3 ...; do
git tag -d $tag
git push origin :refs/tags/$tag
done
Useful if you have already run a git add and are trying to
remember the changes you’ve made.
Resource: https://stackoverflow.com/questions/3527856/show-git-diff-on-file-in-staging-area
This example will squash the most recent two commits and push the new commit to main, overwriting what was there previously:
branch=main
n=2
# Squash most recent n commits together
git reset --soft HEAD~${n}
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
git push origin +${branch}
With rebasing on the current branch:
Resources:
git fetch upstream
git checkout $BRANCH_IN_FORK_TO_UPDATE
git rebase upstream/$BRANCH_IN_FORK_TO_UPDATE
git rebase --continue
git push origin main --force-with-lease # push fork changes
git check-ignore -v filename
Resource: https://stackoverflow.com/questions/12144633/explain-which-gitignore-rule-is-ignoring-my-file
Add a / in front, i.e. /mose
Resource: https://stackoverflow.com/questions/3637660/how-to-exclude-file-only-from-root-folder-in-git
This example ignores everything in the current directory except for the .gitignore and .chicken files
This is useful if you need to track a file that’s over 100MB in size. It’s important to follow these steps before you attempt to incorporate the large file into the repo.
git lfs install
git lfs track "large.file"
git add .gitattributes
git add large.file
git commit -m "Message"
git push origin <branch>
Resource: https://git-lfs.github.com/
This is useful if you want to track a file that’s over 100MB in size, but don’t want to use git-lfs anymore because it’s priced ridiculously (consider s3 as a cheaper alternative).
## Delete all instances of the file in git history
bfg --delete-files <file>
## Uninstall git-lfs from the repo
git lfs uninstall
git rm .gitattributes
## Push the changes
git push origin +master
Resource: https://dustinfreeman.org/blog/rip-lfs/
Resource: https://stackoverflow.com/questions/424071/how-to-list-all-the-files-in-a-commit
COMMIT_ID=0a0aa000a00000aaa0009b89f00a0a000c0005b6
DIR_TO_RETRIEVE=existed_previously
git checkout $COMMIT_ID -- $DIR_TO_RETRIEVE
git show <commit id>:/path/to/file
git diff origin/master..HEAD
Resource: https://stackoverflow.com/questions/2016901/viewing-unpushed-git-commits
Delete remote branch:
git push origin --delete <branch-name>
Delete local branch:
git branch -D <branch-name>
You don’t want the whole repo, just a specific directory. Seems sensible, this covers how to do it. Note that this is only available as of git 2.19.
git clone \
--depth 1 \
--filter=blob:none \
--no-checkout \
https://github.com/cirosantilli/test-git-partial-clone \
;
cd test-git-partial-clone
git checkout master -- d1
Very useful if you make changes but don’t have a remote git repo to push your commits to.
Show source line diffs and output to a file:
git show <COMMIT ID> | tee output
Apply the patch in the output file:
Super fast tool that is very useful for finding stuff quickly in a repo.
This example will look for the word auth in all tracked files that end with .py:
git grep -n "auth" -- '*.py'
n: Prefix the line number for matching lines
An example to search all tracked .c and .h files for time_t:
git grep 'time_t' -- '*.[ch]'
Resource: https://github.com/awslabs/git-secrets
This example is for the Sliver c2, but you can obviously modify it to meet your needs:
AUTHOR='BishopFox'
REPO_NAME='sliver'
curl -s "https://api.github.com/repos/$AUTHOR/$REPO_NAME/releases/latest" \
| jq -r '.assets[].browser_download_url'
Resource: https://gist.github.com/steinwaywhw/a4cd19cda655b8249d908261a62687f8
wget -q -O $binary_name $binary_url
Resource: https://stackoverflow.com/questions/25923939/how-do-i-download-binary-files-of-a-github-release
This requires a fine-grained personal access token
with the delete:packages and read:packages permissions.
ORG=CowDogMoo
CONTAINER=old-and-useless
export CR_PAT=# personal access token goes here
curl -X DELETE -H "Authorization: Bearer $CR_PAT" https://api.github.com/orgs/$ORG/packages/container/$CONTAINER
-p: Show the diff between each revision and its parent
Resources: https://stackoverflow.com/questions/278192/view-the-change-history-of-a-file-using-git-versioning
git diff abc123 def456 -- path/to/file.
In this example, abc123 and def456 are the revision IDs.
BR1=dev
BR2=main
git diff "${BR1}" "${BR2}" -- path/to/file.
Resource: https://stackoverflow.com/questions/2364147/how-to-get-just-one-file-from-another-branch
find . -type d -iname ".git"
Resource: https://www.cyberciti.biz/faq/unix-linux-centos-ubuntu-find-hidden-files-recursively/
This example will run git diff for all modified *.yaml files in a repo:
for file in $(git diff --name-only | grep '\.yaml$'); do
git diff "$file"
done
This is useful if you get an error message about diverged branches or have a merge conflict.
git fetch origin
git reset --hard origin/master
git checkout $COMMIT_ID -- path/to/the/folder/
FILE=./scripts/moveFile.sh
git update-index --chmod +x $FILE
Resource: https://github.community/t/how-to-execute-a-script-file-using-github-action/16830/4
If you’ve started working in the wrong branch, you can do the following to move it to a new one:
git checkout -b <new-branch-name>
In this example, upstream trunk is on main:
UPSTREAM_TRUNK=upstream/main
git checkout -b $NEW_BRANCH_NAME $UPSTREAM_TRUNK
git mv -f yOuRfIlEnAmE yourfilename
TAG=v1.0.0
git tag -d "${TAG}"
git push --delete origin "${TAG}"
Resources: https://www.abeautifulsite.net/posts/how-to-delete-a-tag-on-github/ https://devconnected.com/how-to-delete-local-and-remote-tags-on-git/
git cherry-pick is a powerful command that allows you to take a commit from
one branch and apply it to another branch. This can be thought of as a more
surgical version of git merge as it applies a specific commit rather
than multiple commits.
Imagine you’ve accidentally committed your changes to the wrong branch, but you
want those changes in a different branch.
Here’s how you can use git cherry-pick to resolve this:
First, identify the hash of the commit you want to move.
This is a unique identifier for each commit. You can view this via git log.
Check out to the branch where you want to apply the commit:
git checkout $DESIRED_BRANCH
Use git cherry-pick to apply the commit to the desired branch:
git cherry-pick $DESIRED_BRANCH
Now, the commit has been applied to the desired branch, you should go back to the original branch and remove the commit there:
git checkout $ORIGINAL_BRANCH
git reset --hard HEAD~1
git tag -a v1.0.0 -m "Releasing version v1.0.0"
git push origin v1.0.0
Resource: https://dev.to/neshaz/a-tutorial-for-tagging-releases-in-git-147e
Make sure you are in the branch that references the new commit(s)
Add your changes to the tagged release:
# Example tag
TAG='v1.0.8'
git tag -f -a "${TAG}"
Push your new commit and force push your moved tag:
git push origin main
git push origin -f "${TAG}"
cd /git/directory
if [[ `git status --porcelain` ]]; then
# Changes
else
# No changes
fi
Create a GitHub Personal Access Token
export PAT=# personal access token goes here
export REPO=# repo name goes here
export AUTHOR=# author name goes here
curl -H "Accept: application/vnd.github+json" \
-H "Authorization: token ${PAT}" \
"https://api.github.com/repos/${AUTHOR}/${REPO}/releases"
Resource:
Create a GitHub Personal Access Token
Set the $PAT:
export PAT=# personal access token goes here
Create dl.sh (modified version of gh-dl-release,
see resources below for link):
#!/usr/bin/env bash
set -ex
# author/repo goes here, e.g. l50/goutils:
REPO=''
# the name of the release asset file, e.g. build.tar.gz
FILE=''
# tag name or the word "latest"
VERSION=$1
GITHUB="https://api.github.com"
alias errcho='>&2 echo'
if [[ -z "${PAT}" ]]; then
echo 'error: personal access token (PAT) not set'
exit 1
fi
function gh_curl() {
curl -H "Authorization: token $PAT" \
-H "Accept: application/vnd.github.v3.raw" \
$@
}
if [ "$VERSION" = "latest" ]; then
# Github should return the latest release first.
parser=".[0].assets | map(select(.name == \"$FILE\"))[0].id"
else
parser=". | map(select(.tag_name == \"$VERSION\"))[0].assets \
| map(select(.name == \"$FILE\"))[0].id"
fi;
asset_id=`gh_curl -s $GITHUB/repos/$REPO/releases | jq "$parser"`
if [ "$asset_id" = "null" ]; then
errcho "ERROR: version not found $VERSION"
exit 1
fi;
wget -q --auth-no-challenge --header='Accept:application/octet-stream' \
https://$PAT:@api.github.com/repos/$REPO/releases/assets/$asset_id \
-O $2
To use it:
Resources:
#!/bin/bash
set -x
# Update all git directories below current directory or specified directory
GREEN="\033[01;32m" # Success
YELLOW='\033[0;33m' # Informational
RESET="\033[00m" # Normal
DEBUG='false'
DIRS=("$(pwd)" ansible_roles terraform_modules ansible_playbooks)
pull_repos() {
# Read all repos into $git_repos array
mapfile -t git_repos < \
<(find . -type d \( -exec test -d "{}/.git" -a "{}" != "." \; -print -prune \
-o -name .git -prune \))
for r in "${git_repos[@]}"; do
pushd "${r}" || exit
if [[ "${DEBUG}" == "true" ]]; then
echo "Determining if we have the latest version of ${r}"
fi
res=$(git pull origin main 2>/dev/null)
if [[ "${res}" != 'Already up to date.' ]]; then
echo -e "${GREEN}Now Updating ${r}${RESET}"
fi
popd || exit
done
}
# Pull repos in $DIRS
for d in "${DIRS[@]}"; do
echo -e "${YELLOW}Updating repos in ${d}${RESET}"
pushd "${d}" || exit
pull_repos
popd || exit
done
git ls-files | git check-attr -a --stdin | grep git-crypt
I’ve recently started using the gh CLI tool and I’m quite impressed. Here’s my cheat sheet that I hope you’ll find as useful as I do:
Easy mode:
Hard mode (BYO PAT):
Create a GitHub Personal Access Token
Set the expiration date
Check the box next to repo -> click Generate token
Copy the value of the token and set it to the GH_TOKEN env var:
# Add a space in front of the export so that
# your GH TOKEN doesn't show up in your history :)
export GH_TOKEN=tokenvaluecopiedfromgithubgoeshere
Run the following command to complete the process:
echo "${GH_TOKEN}" > .githubtoken
unset GH_TOKEN
gh auth login --with-token < .githubtoken
rm .githubtoken
Confirm authentication success:
# Get the current OS and architecture
os=$(uname | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
# Map the architecture name to the one used by GitHub
if [[ "$arch" == "x86_64" ]]; then
arch="amd64"
elif [[ "$arch" == "aarch64" ]]; then
arch="arm64"
fi
# Adjust OS name for MacOS
if [[ "$os" == "darwin" ]]; then
os="macOS"
fi
AUTHOR='cli'
REPO_NAME='cli'
# Get the latest version from the GitHub API
latest_release="https://api.github.com/repos/$AUTHOR/$REPO_NAME/releases/latest"
all_urls=$(curl -s "$latest_release" | jq -r '.assets[].browser_download_url')
# Filter URLs to match the OS and architecture
download_url=$(echo "$all_urls" | grep "${os}_${arch}" | grep -v 'deb\|rpm\|msi')
checksum_url=$(echo "$all_urls" | grep 'checksums')
# Check if URL exists
if [ -z "$download_url" ]; then
echo "No download URL found for OS: $os, architecture: $arch"
exit 1
fi
# Download the file
curl -sLO "$download_url"
# Extract the filename from the download URL
filename=$(basename "$download_url")
# Download the checksum file
curl -sLO "$checksum_url"
# Verify the checksum
checksum_file=$(basename "$checksum_url")
if [[ "$os" == "macOS" ]]; then
# MacOS uses shasum instead of sha256sum and has different behavior for grep
shasum -a 256 -c <(grep "$filename" "$checksum_file")
else
sha256sum -c --ignore-missing <(grep "$filename" "$checksum_file")
fi
# Extract the downloaded file
extraction_folder="gh_temp"
if [[ "$os" == "macOS" ]]; then
unzip "$filename" -d "$extraction_folder"
else
tar -xvf "$filename" -C "$extraction_folder"
fi
# Check if /usr/local/bin is in the PATH
if echo "$PATH" | grep -q "/usr/local/bin"; then
install_path="/usr/local/bin"
else
# Get the first directory in PATH as the install path
install_path=$(echo "$PATH" | cut -d ':' -f1)
fi
# Extract the version from the filename
version=$(echo "$filename" | sed -e 's/gh_\([0-9.]*\)_.*/\1/')
# Move the binary file to the install path
mv "${extraction_folder}/gh_${version}_${os}_${arch}/bin/gh" "$install_path"
# Clean up the downloaded and extracted files
rm -rf "$filename"
rm -rf "$checksum_file"
rm -rf "$extraction_folder"
Clone my goutils repo:
gh repo clone l50/goutils
Resource: https://github.com/cli/cli/issues/368
This will create a CHANGELOG.md:
NEXT_VERSION=v1.1.3
gh extension install chelnak/gh-changelog
gh changelog new --next-version $NEXT_VERSION
Generate release notes without providing a CHANGELOG.md:
gh release create $NEXT_VERSION --generate-notes
Alternatively, if you created a CHANGELOG.md:
gh release create $NEXT_VERSION -F CHANGELOG.md
ISSUE_ID=4
gh issue close "${ISSUE_ID}"
ACTION_NAME='Run Tests'
gh workflow view "${ACTION_NAME}"
ACTION_NAME='Run Tests'
gh workflow run "${ACTION_NAME}"
Resources:
OS="$(uname | python3 -c 'print(open(0).read().lower().strip())')"
ARCH="$(uname -a | awk '{ print $NF }')"
gh release download -p "*${OS}_${ARCH}.tar.gz"
tar -xvf *tar.gz
gh issue list -L 20 -s "open" | \
grep "Renovate Dashboard" | \
awk -F ' ' '{print $1}' | \
xargs -I{} gh issue close {}
ORG_NAME=CowDogMoo
gh api --paginate "/orgs/$ORG_NAME/repos" \
| jq -r '.[].clone_url' | xargs -L1 git clone
#!/bin/sh
set -e
TOOL_NAME="$1"
TOOL_BINARY="$2"
DOWNLOAD_BASE_URL="$3"
DOWNLOAD_BINARY_FILE="$4"
DOWNLOAD_CHECKSUM_FILE="$5"
SHASUM_IGNORE_MISSING="$6"
SHASUM_ALGO="$7"
TEST_COMMAND="$8"
echo "Installing $TOOL_NAME..."
# Download checksums and binary
curl -L "${DOWNLOAD_BASE_URL}/${DOWNLOAD_CHECKSUM_FILE}" -o checksums.txt
curl -OL "${DOWNLOAD_BASE_URL}/${DOWNLOAD_BINARY_FILE}"
# Verify checksums
shasum ${SHASUM_IGNORE_MISSING} -a ${SHASUM_ALGO} -c checksums.txt
# Install tool
if [ "${DOWNLOAD_BINARY_FILE##*.}" = "deb" ]; then
dpkg -i "${DOWNLOAD_BINARY_FILE}"
elif [ "${DOWNLOAD_BINARY_FILE##*.}" = "gz" ]; then
tar xzf "${DOWNLOAD_BINARY_FILE}"
mv "${TOOL_BINARY}" /usr/local/bin/
else
chmod +x "${DOWNLOAD_BINARY_FILE}"
mv "${DOWNLOAD_BINARY_FILE}" /usr/local/bin/
fi
# Clean up
rm -f checksums.txt "${DOWNLOAD_BINARY_FILE}"
# Verify binary works
eval "${TEST_COMMAND}"
echo "$TOOL_NAME installation complete."
Example:
# Install GitHub CLI
ENV GITHUB_CLI_VERSION 2.27.0
RUN install-tool \
"GitHub CLI" \
"gh" \
"https://github.com/cli/cli/releases/download/v${GITHUB_CLI_VERSION}" \
"gh_${GITHUB_CLI_VERSION}_${TARGET_OS}_${TARGET_ARCH}.deb" \
"gh_${GITHUB_CLI_VERSION}_checksums.txt" \
"--ignore-missing" \
"512" \
"gh --version"
git checkout --orphan latest_branch
git add -A
git commit -am "commit message"
git branch -D main
git branch -m main
git push -f origin main
Resource: https://stackoverflow.com/questions/13716658/how-to-delete-all-commit-history-in-github
Deploy keys are useful when you need to clone another repo in an action. You can also use PAT, although this gives write access to all private repos, which is suboptimal from a security standpoint.
KEY_NAME=deploy-key
KEY_DESCRIPTION='Deploy key'
ssh-keygen -t ed25519 -C "${KEY_DESCRIPTION}" -f "~/.ssh/${KEY_NAME}" -N ''
mv "${KEY_NAME}"* ~/.ssh
Add the public key to the deploy keys of the repo you want to be able to clone
Add the private key as a secret to the action that you want to use the repo with.
Add this section to the action that’s using the deploy key:
- name: Setup with deploy key
run: |
eval `ssh-agent -s`
ssh-add - <<< '${{ secrets.PRIVATE_SSH_KEY }}'
Resources:
Note that this will work for commits that are several commits back in your history.
git revert $COMMIT_HASH
git push origin HEAD
This will run a git pull for any repos in the current directory or below:
ORG_NAME=CowDogMoo
find . -type d -name '.git' \
-exec sh -c 'cd {} && cd .. && \
if [[ $(git config --get remote.origin.url) == *$ORG_NAME* ]]; then \
git pull; fi' \;
# Ensure you are on your feature branch
git checkout my-feature-branch
# Fetch the latest changes from the remote repository
git fetch origin
# Rebase your feature branch onto the latest main branch
git rebase origin/main
# Resolve any conflicts if they arise and stage the changes. Then run:
git rebase --continue
# Once the rebase is successful, push your changes to your remote feature branch
git push -f
In this example, we’re ignoring magefiles/go.mod and magefiles/go.sum
from the output:
git diff --cached -- . ':(exclude)magefiles/go.mod' ':(exclude)magefiles/go.sum'
This example will run git add for all modified *.yaml files in a repo:
git add $(git diff --name-only | grep '\.yaml$')
COMMITS=16
git log -n $COMMITS --oneline
Alternatively, if you want the body as well as the commit message, you can run:
COMMITS=16
git log -n $COMMITS | cat