0

Why are these two commands producing these results:

  1. (master is checked out) git checkout beta git push

  2. (beta is checked out) git push origin beta

I ask because the former results in an error (403) in AWS CodeCommit, and the latter pushes to the branch just fine. Also, I get a warning whenever I checkout beta that I'm +20 commits ahead of the origin branch:

"Your branch is ahead of 'codecommit-origin/beta' by 38 commits."

therealscifi
  • 362
  • 5
  • 12
  • The cause of this issue was because when I was checked out to master, the remote URL was correct, but when I was checkout out to beta, the remote URL changed to the http version of the URL, not the correct ssh version. Correcting the URL (git remote set-url --push ) fixed this, and leads me to believe that the URL of remote depends on which branch is checked out, making the 1st scenario and 2nd scenario different. – therealscifi Jun 14 '17 at 01:14

2 Answers2

1

Note: this answer is for git push in general and not for git with AWS

git push takes in as arguments where you want to send the code (origin), and the branch that you are sending the code from. Thus, if you see in many code examples, git push origin master pushes code to origin from your master branch. If you enter the command git push origin beta, then you push to the beta branch of the remote origin repository from your local beta branch. git checkout is a command that switches the branch you are currently working in. Thus, git checkout beta switches your local repository to the beta branch, and if you make changes and commit them (make sure to commit before switching branches!) they will only change in the beta branch. Likewise, git checkout master switches to your master branch. It does not matter what branch you run git push from, since you specify which branch to push as the second argument.

victor
  • 1,573
  • 11
  • 23
1

It has to do with your git config push.default setting. To see your settings run:

$ git config -l

(keep in mind you can have 3 different git settings: global, system, local. Run the above command with either --global --system or --local to see the values set for each.)

If you just use git push but don't specify where you are pushing to, git will use the rules for the push.default setting. To avoid unintended behavior, always be verbose and specify where you want to push to, ie: git push origin beta

git push.default documentation

BigHeadCreations
  • 1,583
  • 3
  • 16
  • 31