1

I have a buildspec in CodeBuild which downloads 2 branches(develop and refactored_branch) from different repos with the sources referenced in Source in CodeBuild. I have a script that makes some changes by copying some files from develop branch into refactored_branch. When I am done with copying of the files I want to copy all those changes from refactored_branch to another already existing branch (branch_to_be_pushed) which is in the same repo as refactored_branch and push branch_to_be_pushed to github? I tried git checkout branch_to_be_pushed and then git pull refactored branch and even git merge refactored_branch but no luck.The buildspec looks like this:

pre_build:
    commands:
    - cd $CODEBUILD_SRC_DIR
    - pwd
    - git checkout develop
    - cd $CODEBUILD_SRC_DIR_Source2
    - pwd
    - git checkout refactored_branch
    - git config --global user.email $User    
    commands:
       - ./bin/deploy.py -src1=$CODEBUILD_SRC_DIR -src2=$CODEBUILD_SRC_DIR_Source2
  post_build:
    commands:
      - cd $CODEBUILD_SRC_DIR_Source2
      - pwd
      - ls -la
      - git status
      - git branch
      - git checkout branch_to_be_pushed
      - git status
      - git branch
      - git add .
      - git commit -m "push changes"
      - pwd
      - ls -la
      - git push https://$User:$Pass@github.com/xxxxxx/xxxxx-xxxxxx-xxxx.git
Gudzo
  • 639
  • 2
  • 8
  • 21
  • Please provide the build log so we know which command is failing with what error. Is it related to git credentials? Is your build hanging? What is the version you are using on BuildSpec file (0.1 or 0.2?). – shariqmaws Oct 01 '19 at 02:19

1 Answers1

0

push branch_to_be_pushed to github

Simply add the local branch name you want to push, as seen here:

git push https://$User:$Pass@github.com/xxxxxx/xxxxx-xxxxxx-xxxx.git branch_to_be_pushed

You might want to use a PAT though (Personal Access Token) instead of your account password, or an SSH URL based on a dedicated key.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250