Last active
January 12, 2019 09:18
-
-
Save leob/d2766b1ce44c74f8bb57365b370210b0 to your computer and use it in GitHub Desktop.
Git commands that I find personally useful and use often
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# GIT create branches local/remote: | |
git checkout -b my-new-branch | |
git push -u origin my-new-branch | |
git checkout --track origin/my-new-branch | |
# GIT delete branches local/remote: | |
git branch -d -r origin/some-branch | |
# detailed branch listing (local/tracking) | |
git branch -avv | |
git branch -d some-branch | |
# EASY WAY TO CLEANUP UNUSED/STALE LOCAL/REMOTE BRANCHES: | |
git fetch origin --prune | |
# WAY TO "GIT STASH POP WITH 'FORCE'" (from: https://stackoverflow.com/a/3733698) | |
git stash show -p | git apply -3 && git stash drop | |
# CLONE ONLY MASTER AND AFTER THAT ADD SPECIFIC BRANCHES | |
# Clone/pull and track only a single branch (master), not any other branches in the repo | |
git clone https://github.com/someone/something.git -b master --single-branch | |
# Add a specific remote branch to the local repo, and check it out as a tracking branch | |
# (see: https://stackoverflow.com/a/27860061) | |
git remote set-branches --add origin some-branch | |
git checkout --track origin/some-branch | |
# REBASE AND PUSH "WITH LEASE" (https://dev.to/maxwell_dev/the-git-rebase-introduction-i-wish-id-had) | |
git checkout master | |
git pull | |
git checkout some-branch | |
git rebase master | |
git push --force-with-lease origin some-branch | |
# Then merge to master - use 'temp branch' for checking (see: https://stackoverflow.com/questions/7484199/how-to-test-a-merge-without-actually-merging-first/18701022) | |
git checkout master | |
# Use a temp branch: https://stackoverflow.com/a/21828024 | |
git checkout -b trial_merge | |
git merge some-branch | |
# Now check the diffs between 'trial_merge' and 'mater' (or, if the merge was a "fast forward" then we can assume that all is fine ...) | |
git checkout master | |
# Next, delete the temp branch and perform the actual merge (and push the master branch) | |
git branch -D trial_merge | |
git merge some-branch | |
git push origin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment