Git新手求助:如何将修改代码从原分支迁移至指定新分支
Fixing Git Push Issues for Your Personal Branch
Hey there! Let's get your code pushed to the right branch without any hassle. Since you're new to Git, I'll walk you through two reliable approaches—command line (great for troubleshooting) and fixing the GitHub Desktop workflow you tried earlier.
Command Line Steps (Quick & Reliable)
If you're comfortable with a terminal, this method gets the job done fast:
- First, make sure all your local changes are committed. Run
git statusto check—if you see uncommitted files, run:git add . git commit -m "Describe your changes here (e.g., 'Add user profile UI updates')" - Next, add your personal repository as a new remote. Use this command with your actual repo address:
git remote add personal https://my.company.com/13179069/WebApp.git - Finally, push your local
DEVbranch to your personal repository'sDEVbranch:
If you get a "non-fast-forward" error, it means the remote branch has changes you don't have—rungit push personal DEVgit pull personal DEVto merge them first, then push again.
Fixing GitHub Desktop Issues
If you prefer the GUI, here's how to configure it to push to your personal branch:
- Open GitHub Desktop and select your WebApp repository.
- Go to the Repository menu > Repository Settings.
- In the Remotes section, click Add. Name the remote something like
personal, paste your repo URL (https://my.company.com/13179069/WebApp.git), then click Add Remote. - Back on the main screen, confirm you're on the
DEVbranch (check the top-left corner—if not, use the branch dropdown to switch to it). - Click the dropdown arrow next to the Push button (it might say "Push to origin" right now). Select your new
personalremote, then choose to push to theDEVbranch. - If you see a prompt about needing to pull changes first, follow the on-screen steps to merge any remote updates into your local code before pushing.
Pro Tip for Future Work
When you need to get the latest changes from the main DEV branch later, just run:
git pull origin DEV
(Assuming origin is the name of the main repository remote—this is the default when you first clone it.)
内容的提问来源于stack exchange,提问作者Raghuveer
相关产品推荐
相关产品推荐

