keeer
keeer

Reputation: 863

Writing changes to a remote branch with git

I'm quite new to git but I've got my head round the process. Seems to be clone (if it's new), pull, add, commit push... This has worked fine for the most part as the remote repo has a branch called master as well (thus git push works without any additional commands).

Now I'm in a situation where the repo I've cloned has multiple branches, e.g:

* master
  remotes/origin/HEAD
  remotes/origin/example
  remotes/origin/master

I'd like to add my changes to the example branch and test. If this is successful I'd then like to merge it with the master branch.

What commands do I need to run to accomplish these goals?

Upvotes: 0

Views: 87

Answers (3)

Briana Swift
Briana Swift

Reputation: 1217

Adding to Jimmy's answer-

  1. Switch to the branch you want to work on with git checkout <branchname>, like git checkout example.

  2. Do the work on that branch with git add, git commit -m "enter commit message here". Check often with git status.

  3. Reverse merge master to avoid any merge conflicts: git merge master.

  4. Do any of the tests you'd like to from this branch.

  5. Switch to master: git checkout master, and merge into master, git merge example.

  6. Push the changes to the remote branch: git push -u example.

Upvotes: 3

Rahul Chauhan
Rahul Chauhan

Reputation: 59

First do git checkout example. Then do all other commands as you will be on example branch.

Upvotes: 1

Jimmy Kane
Jimmy Kane

Reputation: 16825

How about this ?

  1. Switch to example
  2. Merge master so it's up to date (optional)
  3. Change stuff and test
  4. Commit them
  5. Switch to master
  6. Merge example in mmaster
  7. Push to origin master (optional also example)

Upvotes: 1

Related Questions