Skip to content

Instantly share code, notes, and snippets.

@michaelkarrer81
Last active February 26, 2024 21:19
Show Gist options
  • Save michaelkarrer81/12de4693a632002f5b6963f80ff7ff9b to your computer and use it in GitHub Desktop.
Save michaelkarrer81/12de4693a632002f5b6963f80ff7ff9b to your computer and use it in GitHub Desktop.
[GIT Cheat Sheet] Git commands and procedures #git
# Show status of repository
git status
# Show all branches
git branch -avv
# Create a branch
git branch ${new_branch_name}
# Checkout a branch
git checkout ${branchname}
# Add files to stage for next commit
git add [PFAD]
# Create a commit with a comment
git commit -m "[CHG] addon_name MSG"
# Push to origin
git push
# Fetch changes from origin
git pull
git fetch --tags
# ------------
# COMMON TASKS
# ------------
# Total reset and and cleanup of a repository and all of it's submodules
git pull
git fetch --tags
git clean -xfdf
git reset --hard
git config --file=.gitmodules -l # Makes git config recognise changes in .gitmodules in case of a branch or URL change
git submodule sync # Syncs submodule urls in case of a branch change
# git submodule update --init --recursive --remote # ATTENTION only do this after branch/URL change in .submodules !!!
git submodule foreach --recursive git fetch # git fetch
git submodule foreach --recursive git clean -xfdf
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
git submodule foreach --recursive git clean -xfdf
git submodule foreach --recursive git reset --hard
git submodule update -f
# -------------------
# DEVELOPMENT PROCESS
# -------------------
# ATTENTION: You should do a total reset and cleanup of your repository before this process
# and before and after "rebase" and "merge"
# 1.) Create a new branch from "your master branch" and checkout new branch
git branch "work_in_progress"
git checkout "work_in_progress"
# 2.) Push new branch to origing (e.g.: github) to inform other devs
git push origin "work_in_progress"
# 3.) Do local dev and "add" and "commit" the changes
git add ...
git commit -m "..."
# 4.) Optional: Rebase on master before step 5 to prevent merge problems
# HINT: You can also do this multiple times if needed while developping on the new branch
git rebase "your master branch"
# 5.) Merge the dev branch back into master
git checkout "your master branch"
git merge "work_in_progress"
# ----------
# SUBMODULES
# ----------
# Add a submodule
git submodule add -b master https://github.com/ether/etherpad-lite.git etherpad-lite
# Initialize a submodule
git submodule update --init ./etherpad-lite
# Initialize all submodules (download)
git submodule update --init --recursive
# Update a submodule
git submodule update --remote --rebase ./etherpad-lite
# Update all submodules to latest commits of branch from remote repository
git submodule update --remote --rebase --recursive
# Remove a submodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment