My team squashes feature commits and rebases the primary branch to keep our history linear.
For this question let's say we have 3 branches
- dev (default/primary)
- prod (once the commits are verified we deploy using this branch. During a deployment we create a commit, so prod is then merged into dev)
- my-feature
git checkout dev
git checkout -b my-feature
// do work
git commit -m "some work"
// another commit merges/is added to dev
git pull --rebase origin dev
git push origin HEAD
That last command pushes the current branch to the remove branch.
Now let's say I'm doing a deployment
git checkout prod
git status
On branch prod
Your branch is behind 'remotes/origin/prod' by 2 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
git pull --rebase origin HEAD
From xxx
* branch HEAD -> FETCH_HEAD
Successfully rebased and updated refs/heads/prod.
git status
On branch prod
Your branch is ahead of 'remotes/origin/prod' by 3 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
Why did git pull --rebase origin HEAD
pull from the dev
branch when I'm on the prod
branch? Is that normal?
If I leave off HEAD I get what I expect (prod == origin/prod)
git pull --rebase origin
I've noticed when I'm on my feature branch .git/HEAD
holds the value I expect...
git checkout my-feature
cat .git/HEAD
ref: refs/heads/my-feature
git checkout prod
cat .git/HEAD
ref: refs/heads/dev
So the question is, why is HEAD
different for the prod
branch?
I frequently push my feature branch with git push -f origin HEAD
, so I really don't want to find one day it's trying to push to our dev branch.
I don't think it should matter, but we use GitLab as our host.
This question is similar, but all of the top answers describe the reverse of what I'm experiencing
- HEAD is just a special pointer that points to the local branch you’re currently on.
- Head is your current branch
- HEAD always refers to the most recent commit on the current branch.
- HEAD is the "tip" of the current branch.
- HEAD is a symbolic reference pointing to wherever you are in your commit history.
So the question stands, why does this happen:
git checkout prod
cat .git/HEAD
ref: refs/heads/dev