Another way to squash all your commits is to reset the index to master:
git checkout yourBranch git reset $(git merge-base master $(git branch --show-current)) git add -A git commit -m "one commit on yourBranch"
This isn’t perfect as it implies you know from which branch “yourBranch” is coming from.
Note: finding that origin branch isn’t easy/possible with Git (the visual way is often the easiest, as seen here).
Note: git branch --show-current
has been introduced with Git 2.22 (Q1 20219).
EDIT: you will need to use git push --force
Karlotcha Hoa adds in the comments:
For the reset, you can do
git reset $(git merge-base master $(git rev-parse --abbrev-ref HEAD))
[That] automatically uses the branch you are currently on.
And if you use that, you can also use an alias, as the command doesn’t rely on the branch name.
Related Posts:
- Git: How do I force “git pull” to overwrite local files?
- Differences between git pull origin master & git pull origin/master
- How do I rename a local Git branch?
- How do I discard unstaged changes in Git?
- Undo git pull, how to bring repos to old state
- Undo git pull, how to bring repos to old state
- Is it better to create a Git repository at the root level or in the WordPress theme directory?
- WordPress and Git: How does Git interact with your IDE? [closed]
- How do I delete a Git branch locally and remotely?
- How do I delete a Git branch locally and remotely?
- How do I rename a local Git branch?
- How do I undo the most recent local commits in Git?
- How can I switch to another branch in git?
- How do I discard unstaged changes in Git?
- Git: How do I force “git pull” to overwrite local files?
- Download single files from GitHub
- How can I make git accept a self signed certificate?
- How can I revert multiple Git commits (already pushed) to a published repository?
- What does “Git push non-fast-forward updates were rejected” mean?
- What is the difference between ‘git pull’ and ‘git fetch’?
- Git: cannot do a partial commit during a merge (SourceTree)
- Git: How do I force “git pull” to overwrite local files?
- What is the meaning of git reset –hard origin/master?
- How can I reset or revert a file to a specific revision?
- Else clause on Python while statement
- Delete all local git branches
- Why does ‘git commit’ not save my changes?
- How can I undo git reset –hard HEAD~1?
- Set up git to pull and push all branches
- git push to specific branch
- Get changes from master into branch in Git
- Invalid VCS root mapping – 3 errors on my project
- Updates were rejected because the remote contains work that you do not have locally
- how to reset develop branch to master
- Do I commit the package-lock.json file created by npm 5?
- Rebasing remote branches in Git
- How can I see the changes in a Git commit?
- What is the Git equivalent for revision number?
- How can I delete all Git branches which have been merged?
- difference between git merge origin/master and git pull
- What’s a good (free) visual merge tool for Git? (on windows)
- Getting Started with Subversion, Git, or similar Version Control System to keep a History of my Files? [closed]
- Best way to version control WordPress template files?
- Should I use SVN or Git?
- WordPress Health Tool reporting version control as a critical issue
- storing database in version control
- Versioning and your WordPress site?
- Pull latest stable release via git [closed]
- How to make changes on WordPress site locally on live site?
- How should I be handling my theme version numbering?
- Version control with a team of non-developers
- Painless way to track remote Git repo for WordPress updates
- Questions about Git and WordPress [duplicate]
- How to change version numbers in themes from Official repository?
- Checking for a new version from WP Repos
- How to rename the wp-config.php file once under version control?
- When developing entire sites for clients, is it viable to version control the entire site? [duplicate]
- WordPress project under Mercurial, what’s an appropriate .hgignore file?
- How to use one git (github) repository for version control for multiple themes
- version control for wordpress? (wordpress folder and database at same time)
- Revision History for Entire WordPress Site
- If you already have a copy of the code, is there any reason to create a feature branch?
- How to use Git Revert
- How do I properly force a Git push?
- How to remove local (untracked) files from the current Git working tree
- How to modify existing, unpushed commit messages?
- Git pushing to remote branch
- How to revert a merge commit that’s already pushed to remote branch?
- How do I resolve git saying “Commit your changes or stash them before you can merge”?
- How do I rename both a Git local and remote branch name?
- git : Pull is not possible because you have unmerged files
- Why does git say “Pull is not possible because you have unmerged files”?
- Git error on commit after merge – fatal: cannot do a partial commit during a merge
- Is there a “theirs” version of “git merge -s ours”?
- Meaning of the GitHub message: push declined due to email privacy restrictions
- Git Bash won’t run my python files?
- Hard reset of a single file
- Not a valid object name: ‘master’
- Git Push ERROR: Repository not found
- “Unable to find remote helper for ‘https'” during git clone
- Why does Git tell me “No such remote ‘origin'” when I try to push to origin?
- Unity Collaborate vs GitHub
- SourceTree keeps asking for Github password
- How to change the license for a project at Github?
- Git push existing repo to a new and different remote repo server?
- How to keep a branch synchronized/updated with master?
- Specify an SSH key for git push for a given domain
- How do I “un-revert” a reverted Git commit?
- git push not send changes to remote git repository
- How to use Git and Dropbox together?
- Git: Where exactly is the “working directory”?
- What exactly does the “u” do? “git push -u origin master” vs “git push origin master”
- git and local wordpress: how to handle wordpress updates?
- Deploying Updated or New Plugins That Modify the wp_options Table
- Setting up Version Control for WordPress plugin development
- SymmetricDS in dev + prod workflow?
- Is there a plugin for versioning files in the theme (style , .js and .php files)?
- Plugin updated pushed with git break site
- Display GitLab repositories of the logged in user on a page
- How to make a copy of a local wordpress build in MAMP?