Nick.Mc
Nick.Mc

Reputation: 19194

Correct order of operations to get changes into a remote branch

I'm using Git in Azure DevOps

I have cloned code from main to a local repo

I've made a bunch of changes in my local repo on the main branch

I need to commit these changes, but they need to end up in a new branch (local and remote)

the main branch can't be committed to directly in remote

What's the correct order to do this? I've been burnt many times by Git so I want to check with the experts before I do anything

Happy to do this all on Git command line

I'm concerned that if I commit to local main then make a local branch, when I try to push that branch back to remote, the original "main" branches won't match and it won't let me push to remote

I'm considering the brute force approach of

  1. Backup my local code and ungit
  2. Make a branch in remote and clone locally
  3. Copy my code over the top of local

But maybe there is a better way.

Upvotes: 0

Views: 121

Answers (1)

Godana Emiru
Godana Emiru

Reputation: 48

Run

git branch 'name_of_new_branch'

to create the new branch locally.

Then run

git checkout 'name_of_new_branch'

to enter the new branch.

Thereafter, run

git add . && git commit -m 'message_of_your_commit'

to commit changes locally

Then finally run

git push origin 'name_of_your_branch'

to push changes to remote branch

Upvotes: 1

Related Questions