Dear All I have two questions
1- I did not change the branch and did my changes in main branch now I want to remove these changes from main branch and transfer them to ABC branch , I have commited all thoses changes as well but I did not push these commiited changes to remote main branch.
2-My project which I clone from the git is producing issues and errors but I have local backup of the project in another drive which works fine but it is not connected with git , so How I can get the previous git clone copy working as the local copy works as the git remote repository is also shared with lot of other guys so I do not want to put my working repo(local backup) repo on git and invite all of them agian .
Sarthak VarshneyPosted May 27, 2024, 9:34 AM
Got it, let's adjust the approach to ensure that the
ABCbranch has all the changes from both themainbranch and the existingABCbranch.1. Removing Changes from Main and Applying Them to ABC Branch
Stash your changes on the
mainbranch:ABCbranch:ABCbranch:mainbranch:mainbranch to the previous commit (before your changes):Adjust
HEAD~1to however many commits you want to remove from themainbranch. If you made multiple commits, replace1with the number of commits.This way, your changes are transferred to the
ABCbranch, and themainthe branch is restored to its previous state.2. Making a Git Clone Copy Work Like a Local Backup
To align your problematic Git clone with your working local backup, follow these steps:
Backup your current Git clone (just in case):
Now, your Git clone should work like your local backup but still be connected to the remote repository. You can pull changes from the remote repository as needed without affecting your local working state.
Additionally, you might want to check for any untracked files or changes that are not committed yet:
This way, you ensure everything is in sync, and you can commit and push changes without disrupting the shared repository environment.
PakeezaPosted May 26, 2024, 7:55 AM
Dear Sarthak Varshney thanks for the quick response about the point # 01 you guided I got it but the issue is if I am creating a new branch from main branch then I got it will have the changes which I dont want to do in main branch and then I reset all changes on main branch , but the issue is the other branch in which I have to made changes is different then main branch so creating a new branch from main will not have my changes which were done by other developers in ABC branch so I get struck
Sarthak VarshneyPosted May 26, 2024, 1:54 AM
1. Transferring Changes from Main Branch to ABC Branch
Since you have committed changes to the
mainbranch but haven't pushed them to the remote repository, you can move these changes to a new branch (ABC) as follows:Create a new branch from the current state of the
mainbranch:Go back to the
mainbranch:mainbranch to the previous commit (before your changes):HEAD~1to however many commits you want to remove from themainbranch. If you made multiple commits, replace1with the number of commits.Now, your changes are in the
ABCbranch, and themainbranch is restored to its previous state.2. Making a Git Clone Copy Work Like a Local Backup
To align your problematic Git clone with your working local backup, follow these steps:
Backup your current Git clone (just in case):
Now, your Git clone should work like your local backup but still be connected to the remote repository. You can pull changes from the remote repository as needed without affecting your local working state.
Additionally, you might want to check for any untracked files or changes that are not committed yet: