ℹ️ 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.1 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://linuxhint.com/move-commit-to-another-branch-in-git/ |
| Last Crawled | 2026-04-05 07:12:35 (1 day ago) |
| First Indexed | 2022-10-16 22:28:18 (3 years ago) |
| HTTP Status Code | 200 |
| Meta Title | How to Move Commit to Another Branch in Git – Linux Hint |
| Meta Description | To move commit, check log history, create new branch. Update last commit file and add it. Run “$ git reset --keep HEAD” command and switch branch. |
| Meta Canonical | null |
| Boilerpipe Text | Multiple files with different types and codes can be saved via branching after being committed in Git. Users can create, update, and remove the branches from the directory. Sometimes, you may encounter a situation where it is required to do some work and commit to a specific branch, but after committing changes, you realize that the commit has been made to the wrong branch mistakenly. In such a situation, you must move the commit to another branch.
This manual will explain the method to move commits to any branch in Git.
To move commits to another branch in Git, first, check the reference log history of the Git repository using the “
$ git log –oneline
” command. Then, check out a new branch. Next, update the last commit file and track it to the Git repository using the “
$ git add .
” command. Lastly, execute the “
$ git reset –keep HEAD
” command and switch the branch.
Let’s move ahead to implement the above-stated scenario!
Step 1: Move to Directory
Navigate to the Git local repository using the “
cd
” command:
$
cd
"C:\Users
\n
azma\Git\demo"
Step 2: Check Log History
Next, list the log history of the Git repository and check the commit or multiple commits which need to be moved:
$
git log
--oneline
Here, all commits of the current branch are listed. We will move the first commit to a new branch:
Step 3: Create Branch
Run the “
git checkout
” to create a new branch in the Git local repository:
$
git checkout
dev
/
new_branch
It can be seen that we have created a new branch named “
dev/new_branch
” and all commits of the current branch will be added to the new branch:
Step 4: Update File
Now, open the file which was recently committed to Git repository:
$
start myfile.txt
Enter some text to the file and press “
CTRL + S
” to save it:
Step 5: Track File
Next, execute the “
git add .
” command to track all modifications to the Git repository:
$
git add
.
Step 6: Check Status
After that, check the status of the Git local directory utilizing the provided command:
$
git status
.
According to the below output, our file is updated successfully and ready to commit:
Step 7: Revert Current Branch to Commit
Now, execute the “
git reset
” command with the “
–keep
” option and specify the position as “
HEAD
”:
$
git reset
--keep
HEAD
This command will move the current branch back to commit which you want to move:
Step 8: Switch to New Branch
Execute the “
git checkout
” command with the branch name to switch the current branch to another branch:
$
git checkout
dev
/
new_branch
Step 9: Check Log History
Lastly, check the log history to verify the commit transfer operation:
$
git log
--oneline
The below image indicates that our “
master
” branch commit is successfully moved to the “
dev/new_branch
” branch:
We have provided the method of moving the commit from one branch to another branch in Git.
Conclusion
To move the commit to another branch in Git, first, navigate to the Git local repository and check the log history. Next, create a new branch with the “
$ git checkout <branch>
” command, then open and update the file which was most recently committed. After that, execute the “
$ git status .
” command and move back to the previous commit using “
$ git reset –keep HEAD
”. Lastly, move to the newly created branch. In this manual, we have demonstrated the method to move commits to another branch in Git.
About the author
I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world. |
| Markdown | [Linux Hint](https://linuxhint.com/)
- [Home](https://linuxhint.com/)
- [YouTube](https://www.youtube.com/c/linuxhint/videos)
- [X](https://x.com/LinuxhintTeam)
- [Master Linux in 20 Minutes](https://freepdf.linuxhint.com/20minutes)
- [Pick Our Next Topic (Join Community)](https://www.skool.com/linuxhint-society-5036/about?ref=8045f4a5708942eba221a38e1577b65d)
[Git](https://linuxhint.com/category/git/)
# How to Move Commit to Another Branch in Git
3 years ago
by [Maria Naz](https://linuxhint.com/author/maria_naz/)


Multiple files with different types and codes can be saved via branching after being committed in Git. Users can create, update, and remove the branches from the directory. Sometimes, you may encounter a situation where it is required to do some work and commit to a specific branch, but after committing changes, you realize that the commit has been made to the wrong branch mistakenly. In such a situation, you must move the commit to another branch.
This manual will explain the method to move commits to any branch in Git.
## **How to Move Commit to Another Branch in Git?**
To move commits to another branch in Git, first, check the reference log history of the Git repository using the “**\$ git log –oneline**” command. Then, check out a new branch. Next, update the last commit file and track it to the Git repository using the “**\$ git add .**” command. Lastly, execute the “**\$ git reset –keep HEAD**” command and switch the branch.
Let’s move ahead to implement the above-stated scenario\!
### **Step 1: Move to Directory**
Navigate to the Git local repository using the “**cd**” command:
\$ cd "C:\\Users\\nazma\\Git\\demo"

### **Step 2: Check Log History**
Next, list the log history of the Git repository and check the commit or multiple commits which need to be moved:
\$ git log \--oneline
Here, all commits of the current branch are listed. We will move the first commit to a new branch:

### **Step 3: Create Branch**
Run the “**git checkout**” to create a new branch in the Git local repository:
\$ git checkout dev/new\_branch
It can be seen that we have created a new branch named “**dev/new\_branch**” and all commits of the current branch will be added to the new branch:

### **Step 4: Update File**
Now, open the file which was recently committed to Git repository:
\$ start myfile.txt

Enter some text to the file and press “**CTRL + S**” to save it:

### **Step 5: Track File**
Next, execute the “**git add .**” command to track all modifications to the Git repository:
\$ git add .

### **Step 6: Check Status**
After that, check the status of the Git local directory utilizing the provided command:
\$ git status .
According to the below output, our file is updated successfully and ready to commit:

### **Step 7: Revert Current Branch to Commit**
Now, execute the “**git reset**” command with the “**–keep**” option and specify the position as “**HEAD**”:
\$ git reset \--keep HEAD
This command will move the current branch back to commit which you want to move:

### **Step 8: Switch to New Branch**
Execute the “**git checkout**” command with the branch name to switch the current branch to another branch:
\$ git checkout dev/new\_branch

### **Step 9: Check Log History**
Lastly, check the log history to verify the commit transfer operation:
\$ git log \--oneline
The below image indicates that our “**master**” branch commit is successfully moved to the “**dev/new\_branch**” branch:

We have provided the method of moving the commit from one branch to another branch in Git.
## **Conclusion**
To move the commit to another branch in Git, first, navigate to the Git local repository and check the log history. Next, create a new branch with the “**\$ git checkout \<branch\>**” command, then open and update the file which was most recently committed. After that, execute the “**\$ git status .**” command and move back to the previous commit using “**\$ git reset –keep HEAD**”. Lastly, move to the newly created branch. In this manual, we have demonstrated the method to move commits to another branch in Git.
### About the author


#### Maria Naz
I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.
[View all posts](https://linuxhint.com/author/maria_naz/)
#### RELATED LINUX HINT POSTS
- [Git “Tip of Your Current Branch Is Behind” Error](https://linuxhint.com/git-tip-of-your-current-branch-is-behind/ "Git “Tip of Your Current Branch Is Behind” Error")
- [Git “Support for Password Authentication Was Removed” Error](https://linuxhint.com/git-support-password-authentication-removed/ "Git “Support for Password Authentication Was Removed” Error")
- [Git “Pre-Receive Hook Declined” Error](https://linuxhint.com/git-pre-receive-hook-declined/ "Git “Pre-Receive Hook Declined” Error")
- [Git “Use a Personal Access Token Instead” Error](https://linuxhint.com/git-please-use-personal-access-token-instead/ "Git “Use a Personal Access Token Instead” Error")
- [Delete a Fork in Git](https://linuxhint.com/git-delete-fork/ "Delete a Fork in Git")
- [Git Clone “Support for Password Authentication Was Removed” Error](https://linuxhint.com/git-clone-support-password-authentication-removed/ "Git Clone “Support for Password Authentication Was Removed” Error")
- [“Pull Is Not Possible Because You Have Unmerged Files” Error in Git](https://linuxhint.com/git-pull-not-possible-because-you-have-unmerged/ "“Pull Is Not Possible Because You Have Unmerged Files” Error in Git")
**Linux Hint LLC, bobby@linuxhint.com 1210 Kelly Park Circle, Morgan Hill, CA 95037** [Privacy Policy](https://linuxhint.com/policies-and-privacy/) and [Terms of Use](https://linuxhint.com/terms-of-use/)
- [Home](https://linuxhint.com/)
- [YouTube](https://www.youtube.com/c/linuxhint/videos)
- [X](https://x.com/LinuxhintTeam)
- [Master Linux in 20 Minutes](https://freepdf.linuxhint.com/20minutes)
- [Pick Our Next Topic (Join Community)](https://www.skool.com/linuxhint-society-5036/about?ref=8045f4a5708942eba221a38e1577b65d) |
| Readable Markdown | 
Multiple files with different types and codes can be saved via branching after being committed in Git. Users can create, update, and remove the branches from the directory. Sometimes, you may encounter a situation where it is required to do some work and commit to a specific branch, but after committing changes, you realize that the commit has been made to the wrong branch mistakenly. In such a situation, you must move the commit to another branch.
This manual will explain the method to move commits to any branch in Git.
To move commits to another branch in Git, first, check the reference log history of the Git repository using the “**\$ git log –oneline**” command. Then, check out a new branch. Next, update the last commit file and track it to the Git repository using the “**\$ git add .**” command. Lastly, execute the “**\$ git reset –keep HEAD**” command and switch the branch.
Let’s move ahead to implement the above-stated scenario\!
### **Step 1: Move to Directory**
Navigate to the Git local repository using the “**cd**” command:
\$ cd "C:\\Users\\nazma\\Git\\demo"

### **Step 2: Check Log History**
Next, list the log history of the Git repository and check the commit or multiple commits which need to be moved:
\$ git log \--oneline
Here, all commits of the current branch are listed. We will move the first commit to a new branch:

### **Step 3: Create Branch**
Run the “**git checkout**” to create a new branch in the Git local repository:
\$ git checkout dev/new\_branch
It can be seen that we have created a new branch named “**dev/new\_branch**” and all commits of the current branch will be added to the new branch:

### **Step 4: Update File**
Now, open the file which was recently committed to Git repository:
\$ start myfile.txt

Enter some text to the file and press “**CTRL + S**” to save it:

### **Step 5: Track File**
Next, execute the “**git add .**” command to track all modifications to the Git repository:
\$ git add .

### **Step 6: Check Status**
After that, check the status of the Git local directory utilizing the provided command:
\$ git status .
According to the below output, our file is updated successfully and ready to commit:

### **Step 7: Revert Current Branch to Commit**
Now, execute the “**git reset**” command with the “**–keep**” option and specify the position as “**HEAD**”:
\$ git reset \--keep HEAD
This command will move the current branch back to commit which you want to move:

### **Step 8: Switch to New Branch**
Execute the “**git checkout**” command with the branch name to switch the current branch to another branch:
\$ git checkout dev/new\_branch

### **Step 9: Check Log History**
Lastly, check the log history to verify the commit transfer operation:
\$ git log \--oneline
The below image indicates that our “**master**” branch commit is successfully moved to the “**dev/new\_branch**” branch:

We have provided the method of moving the commit from one branch to another branch in Git.
## **Conclusion**
To move the commit to another branch in Git, first, navigate to the Git local repository and check the log history. Next, create a new branch with the “**\$ git checkout \<branch\>**” command, then open and update the file which was most recently committed. After that, execute the “**\$ git status .**” command and move back to the previous commit using “**\$ git reset –keep HEAD**”. Lastly, move to the newly created branch. In this manual, we have demonstrated the method to move commits to another branch in Git.
### About the author

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world. |
| Shard | 75 (laksa) |
| Root Hash | 6654701801887936675 |
| Unparsed URL | com,linuxhint!/move-commit-to-another-branch-in-git/ s443 |