0

Super nooby question but....

  • So I'm currently in the master branch and have made some changes locally.
  • I don't want my changes to affect master branch but only my branch.
  • How can I commit and push changes made to a branch without ever affecting the master branch?

4 Answers4

3

I'm assuming you want to move these changes to a new/experimental branch

git checkout -b my_new_branch
git commit
1

You can copy your modified files and paste them in another location so you don't lose your changes. Then, revert your changes, switch to the branch you want to commit to, paste your files into the folders they belong to and then commit your changes to the branch.

Nahue
  • 320
  • 2
  • 18
1

If you don't want to affect the master branch, now is the time to create a new branch for your commits to live on.

git checkout -b my_branch
git add .
git commit -m "This commit will be on the `my_branch` branch instead of `master`
Zachary Cross
  • 2,298
  • 1
  • 15
  • 22
1

As others before have said, checkout and commit to a new branch with

git checkout -b mybranch
git add mychangedfiles
git commit

If you already have a remote set up to push to, you can now push your new branch using

git push -u myremote mybranch

This also sets this branch to track that pushed branch on the remote (-u option).

If you have not set up a remote you can do so with

git remote add myremote myremoteurl
Falk
  • 45
  • 6