โน๏ธ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.2 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://linuxhandbook.com/git-move-commit-branch/ |
| Last Crawled | 2026-04-13 02:28:58 (4 days ago) |
| First Indexed | 2024-06-28 15:18:11 (1 year ago) |
| HTTP Status Code | 200 |
| Meta Title | How to Move Commit to Another Git Branch |
| Meta Description | Made a commit to an incorrect branch and now you want to move the commit to the correct branch? Here's how to handle this git situation. |
| Meta Canonical | null |
| Boilerpipe Text | Sh(g)it happens. I mean it is usual to clone the main branch, create or switch to a dev branch and then commit the changes to this dev branch which is merged to the main later.
Imagine you follow the same only you forget to switch to the dev branch and you made the commit to the main branch.
But before pushing, you want to move this commit to the dev branch instead. You should also remove the commit from the main vranch.
Let me help you by showing the steps for:
Moving the commit to the correct branch
Reverting the commit from the incorrect branch
Moving commit to another branch
First, let's address the issue that I encountered:
While working with three branches, I was supposed to make one commit to the
header
branch and another to the
footer
branch.
The first commit to the
header
branch was correct but unfortunately, I made the second commit to the
header
branch instead of the
footer
branch:
When I checked the git log, it was pretty clear to me that I made a commit to the wrong branch:
Now, let's take a look at the steps to move the commit to another branch.
Step 1: Find the hash of the commit
To find the hash of the commit you want to move, you can use the
git log
in the beach where you made a wrong commit.
I made a wrong commit in the
head
branch so I'll be using
git log
there:
git log
Once you find the hash, copy the hash.
Step 2: Switch to the target branch
Next, switch the branch in which you want to move the commit. For that purpose, you can use the
git checkout
command:
git checkout <branch-name>
In my case, I want to move to commit to the
footer
beach, so I'll be using the following:
git checkout footer
Step 3: Move the commit to the target branch
Once you switch to the target branch, use the
git cherry-pick
command along with the hash you copied from the first step:
git cherry-pick <hash>
To verify if the commit was moved or not, you can check the git log:
git log
There you go!
Revert the incorrect commit
When you use the
cherry-pick
command, it does not move the commit but copies the commit to the current branch. So you are still left with the incorrect commit on the first branch.
The solution is to
revert the incorrect commit
.
For that, first switch to the branch in which you made the incorrect commit:
git checkout <branch-name>
In my case, the beach name was
header
so I will be using the following:
git checkout header
Now, if you check the git log, you will still find the incorrect commit which you recently moved using the
git cherry-pick
command:
To revert this commit, you append the hash of the target commit to the
git revert
command as shown here:
git revert <hash>
It will open the text editor telling you it is reverting the commit. It creates another commit without those changes resulting removal of the specified commit.
Close the text editor and that's it:
Once you close the text editor, you will see an output telling you that the commit has been deleted:
There you have it!
Wrapping Up
In this tutorial, I went through how you can move your commit to a different branch and also explained how you can remove the incorrect commit.
I hope you will find this guide helpful. If you have any queries, feel free to leave us a comment. |
| Markdown | [Skip to main content](https://linuxhandbook.com/git-move-commit-branch/#sx-main)
[](https://linuxhandbook.com/)
- [๐ Books](https://linuxhandbook.com/ebooks/)
- [๐ Courses](https://linuxhandbook.com/courses/)
- [๐ฉโ๐ป Resources](https://linuxhandbook.com/learning-corner/)
- [โจ Latest Tips and Tutorials](https://linuxhandbook.com/blog/)
- [๐ฌ Newsletter](https://linuxhandbook.com/newsletter/)
- [๐ชช Who we are?](https://linuxhandbook.com/about/)
- - [๐ Books](https://linuxhandbook.com/ebooks/)
[๐ Courses](https://linuxhandbook.com/courses/)
[๐ฉโ๐ป Resources](https://linuxhandbook.com/learning-corner/)
[โจ Latest Tips and Tutorials](https://linuxhandbook.com/blog/)
[๐ฌ Newsletter](https://linuxhandbook.com/newsletter/)
[๐ชช Who we are?](https://linuxhandbook.com/about/)
Sign In
Subscribe
/
- [๐ Books](https://linuxhandbook.com/ebooks/)
- [๐ Courses](https://linuxhandbook.com/courses/)
- [๐ฉโ๐ป Resources](https://linuxhandbook.com/learning-corner/)
- [โจ Latest Tips and Tutorials](https://linuxhandbook.com/blog/)
- [๐ฌ Newsletter](https://linuxhandbook.com/newsletter/)
- [๐ชช Who we are?](https://linuxhandbook.com/about/)
- Sign In
- - [How to Undo a Commit in Git](https://linuxhandbook.com/git-undo-commit/)
- [How to Delete Local Git Branch](https://linuxhandbook.com/git-delete-branch-local/)
- [How to Delete Remote Git Branch](https://linuxhandbook.com/git-delete-branch-remote/)
- [Create a New Branch in Git](https://linuxhandbook.com/git-create-branch/)
- [Setup Username and Email in Git](https://linuxhandbook.com/git-set-username-email/)
- [How to Unstage Files in Git](https://linuxhandbook.com/git-unstage/)
- [Switching Branches in Git](https://linuxhandbook.com/git-switch-branch/)
- [Clean Your Git Repository With Git Clean](https://linuxhandbook.com/git-clean/)
- [What is the .git folder?](https://linuxhandbook.com/dot-git-folder/)
- [Undo Git Add and Remove Files from Staging](https://linuxhandbook.com/git-undo-add/)
- [Git Move Commit to Another Branch](https://linuxhandbook.com/git-move-commit-branch/)
- [Git Show Files in a Commit](https://linuxhandbook.com/git-show-files-commit/)
- [Check Git Commit History](https://linuxhandbook.com/git-commit-history/)
- [Amend a Comment in Git](https://linuxhandbook.com/git-amend-commit/)
Using Git
Using Git
[Introduction to Flatpak](https://linuxhandbook.com/flatpak/)
[Learn Firewalld: Manage Linux Firewall with firewall-cmd](https://linuxhandbook.com/firewalld/)
[Getting Started With Nano Editor](https://linuxhandbook.com/learn-nano/)
[Start Learning Vim](https://linuxhandbook.com/learn-vim/)
[Learn Zsh](https://linuxhandbook.com/learn-zsh/)
[Using Git](https://linuxhandbook.com/using-git/)
[Rethinking DevOps](https://linuxhandbook.com/rethinking-devops/)
[Exploring Ansible Modules](https://linuxhandbook.com/ansible-modules/)
[Pentora Box: Pen-Test Practice Labs](https://linuxhandbook.com/pentora-box/)
# Git Move Commit to Another Branch
Sometimes you commit to an incorrect branch and now you want to move the commit to the correct branch. Here's how to handle the situation.

[](https://www.warp.dev/?utm_source=linux_handbook&utm_medium=display&utm_campaign=linux_launch)
Sh(g)it happens. I mean it is usual to clone the main branch, create or switch to a dev branch and then commit the changes to this dev branch which is merged to the main later.
Imagine you follow the same only you forget to switch to the dev branch and you made the commit to the main branch.
But before pushing, you want to move this commit to the dev branch instead. You should also remove the commit from the main vranch.
Let me help you by showing the steps for:
- Moving the commit to the correct branch
- Reverting the commit from the incorrect branch
## Moving commit to another branch
First, let's address the issue that I encountered:
While working with three branches, I was supposed to make one commit to the `header` branch and another to the `footer` branch.
The first commit to the `header` branch was correct but unfortunately, I made the second commit to the `header` branch instead of the `footer` branch:

When I checked the git log, it was pretty clear to me that I made a commit to the wrong branch:

Now, let's take a look at the steps to move the commit to another branch.
### Step 1: Find the hash of the commit
To find the hash of the commit you want to move, you can use the `git log` in the beach where you made a wrong commit.
I made a wrong commit in the `head` branch so I'll be using `git log` there:
```
git log
```

Once you find the hash, copy the hash.
### Step 2: Switch to the target branch
Next, switch the branch in which you want to move the commit. For that purpose, you can use the `git checkout` command:
```
git checkout <branch-name>
```
In my case, I want to move to commit to the `footer` beach, so I'll be using the following:
```
git checkout footer
```

### Step 3: Move the commit to the target branch
Once you switch to the target branch, use the `git cherry-pick` command along with the hash you copied from the first step:
```
git cherry-pick <hash>
```

To verify if the commit was moved or not, you can check the git log:
```
git log
```

There you go\!
## Revert the incorrect commit
When you use the `cherry-pick` command, it does not move the commit but copies the commit to the current branch. So you are still left with the incorrect commit on the first branch.
The solution is to [revert the incorrect commit](https://linuxhandbook.com/git-undo-commit/).
For that, first switch to the branch in which you made the incorrect commit:
```
git checkout <branch-name>
```
In my case, the beach name was `header` so I will be using the following:
```
git checkout header
```
Now, if you check the git log, you will still find the incorrect commit which you recently moved using the `git cherry-pick` command:

To revert this commit, you append the hash of the target commit to the `git revert` command as shown here:
```
git revert <hash>
```
It will open the text editor telling you it is reverting the commit. It creates another commit without those changes resulting removal of the specified commit.
Close the text editor and that's it:

Once you close the text editor, you will see an output telling you that the commit has been deleted:

There you have it\!
## Wrapping Up
In this tutorial, I went through how you can move your commit to a different branch and also explained how you can remove the incorrect commit.
I hope you will find this guide helpful. If you have any queries, feel free to leave us a comment.
Updated on Jun 28, 2024
Comments
Share
Copy link
[Share to X](https://x.com/intent/tweet?url=https%3A%2F%2Flinuxhandbook.com%2Fgit-move-commit-branch%2F&text=Git%20Move%20Commit%20to%20Another%20Branch)
[Share to Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Flinuxhandbook.com%2Fgit-move-commit-branch%2F)
[Share to Linkedin](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Flinuxhandbook.com%2Fgit-move-commit-branch%2F)
Copied
[Previous](https://linuxhandbook.com/git-move-commit-branch/)
[Next](https://linuxhandbook.com/git-move-commit-branch/)
## About the author
[ Sagar Sharma](https://linuxhandbook.com/author/sagar/)
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.
[View profile](https://linuxhandbook.com/author/sagar/)
## On this page
[](https://linuxhandbook.com/)
An independent, reader-supported publication focusing on Linux Command Line, Server, Self-hosting, DevOps and Cloud Learning
## Subscribe to our newsletter
Get the latest posts and updates delivered to your inbox.
No spam. Unsubscribe anytime.
Enter your email Subscribe
- [Contact](https://linuxhandbook.com/contact/)
- [Pro Resources](https://linuxhandbook.com/member-resources/)
- [Membership FAQ](https://linuxhandbook.com/membership-faq/)
- [Cheat Sheets](https://linuxhandbook.com/cheatsheets/)
- [Privacy Policy](https://linuxhandbook.com/privacy-policy/)
- [Write for Us](https://linuxhandbook.com/write-for-us/)
- [Terms of Use](https://linuxhandbook.com/terms/)
[Linux Handbook](https://linuxhandbook.com/) ยฉ 2026 ยท Hosted on [DigitalOcean](https://m.do.co/c/d58840562553) (get \$200 in FREE credits). Published with [Ghost](https://ghost.org/?via=abhishek70) and [Spiritix](https://spiritix.co/?aff=GNoD0) |
| Readable Markdown | [](https://www.warp.dev/?utm_source=linux_handbook&utm_medium=display&utm_campaign=linux_launch)
Sh(g)it happens. I mean it is usual to clone the main branch, create or switch to a dev branch and then commit the changes to this dev branch which is merged to the main later.
Imagine you follow the same only you forget to switch to the dev branch and you made the commit to the main branch.
But before pushing, you want to move this commit to the dev branch instead. You should also remove the commit from the main vranch.
Let me help you by showing the steps for:
- Moving the commit to the correct branch
- Reverting the commit from the incorrect branch
## Moving commit to another branch
First, let's address the issue that I encountered:
While working with three branches, I was supposed to make one commit to the `header` branch and another to the `footer` branch.
The first commit to the `header` branch was correct but unfortunately, I made the second commit to the `header` branch instead of the `footer` branch:

When I checked the git log, it was pretty clear to me that I made a commit to the wrong branch:

Now, let's take a look at the steps to move the commit to another branch.
### Step 1: Find the hash of the commit
To find the hash of the commit you want to move, you can use the `git log` in the beach where you made a wrong commit.
I made a wrong commit in the `head` branch so I'll be using `git log` there:
```
git log
```

Once you find the hash, copy the hash.
### Step 2: Switch to the target branch
Next, switch the branch in which you want to move the commit. For that purpose, you can use the `git checkout` command:
```
git checkout <branch-name>
```
In my case, I want to move to commit to the `footer` beach, so I'll be using the following:
```
git checkout footer
```

### Step 3: Move the commit to the target branch
Once you switch to the target branch, use the `git cherry-pick` command along with the hash you copied from the first step:
```
git cherry-pick <hash>
```

To verify if the commit was moved or not, you can check the git log:
```
git log
```

There you go\!
## Revert the incorrect commit
When you use the `cherry-pick` command, it does not move the commit but copies the commit to the current branch. So you are still left with the incorrect commit on the first branch.
The solution is to [revert the incorrect commit](https://linuxhandbook.com/git-undo-commit/).
For that, first switch to the branch in which you made the incorrect commit:
```
git checkout <branch-name>
```
In my case, the beach name was `header` so I will be using the following:
```
git checkout header
```
Now, if you check the git log, you will still find the incorrect commit which you recently moved using the `git cherry-pick` command:

To revert this commit, you append the hash of the target commit to the `git revert` command as shown here:
```
git revert <hash>
```
It will open the text editor telling you it is reverting the commit. It creates another commit without those changes resulting removal of the specified commit.
Close the text editor and that's it:

Once you close the text editor, you will see an output telling you that the commit has been deleted:

There you have it\!
## Wrapping Up
In this tutorial, I went through how you can move your commit to a different branch and also explained how you can remove the incorrect commit.
I hope you will find this guide helpful. If you have any queries, feel free to leave us a comment. |
| Shard | 46 (laksa) |
| Root Hash | 392173076776213246 |
| Unparsed URL | com,linuxhandbook!/git-move-commit-branch/ s443 |