1

I am a member of a Github repository where there are three branches, master, dev and deployment.

I cloned the repository on my local computer with: git clone git@github.com:COMPANY/repo.git

What I need to do is to merge the changes that were pushed in the dev branch into the master branch, and then the master branch into the deployment branch. My issue is that I only see the master branch on my local clone.

The way I tried to do what is required is as follows:

  1. I created a dev branch and a deployment branch on my local repository with: git checkout -b dev and git checkout -b deployment.

  2. I pulled the dev branch and deployment branch from the origin with: git pull origin dev and git pull origin deployment.

  3. I switched to the master branch(git checkout master) and I merged the dev branch into it: git merge dev.

  4. Then I switched to the deployment branch(git checkout deployment) and I merged the master branch into it: git merge master.

Is this the right procedure to do it or is there a better way?

How can I push all the changes from the two merged branches back to the origin on Github?

argin
  • 52
  • 4
  • Take a look at this answer on how to fetch remote branches: http://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches – Buddy Jul 15 '15 at 22:45
  • There may be issues if you created a branch locally with the same name as the one on remote -- is this the case? If so, you probably meant to modify the remote branches (that apparently you can't see). – rholmes Jul 15 '15 at 22:48

1 Answers1

1

I fear you have used the wrong order of steps. You shouldn't have created the dev and deployment branches with git checkout -b dev. This will create local branches that branch off of your current branch - this is probably not what you want.

The clean way would have looked like this:

# Clone the repo
git clone git@github.com:COMPANY/repo.git

# Fetch everything, just to be sure
git fetch --all

# Take a look at the available branches
# This should list the remote dev and deployment branches in the form 'remotes/origin/dev'
git branch -a

# Now simply check out the dev branch without creating a new branch
git checkout dev

Git knows that if there is a remote branch called dev and you don't have a matching local branch, that it should use the remote one when you do a git checkout dev (without the -b switch!). It will automatically create a new local dev branch from the remote dev branch.

nwinkler
  • 52,665
  • 21
  • 154
  • 168