3 ms·
> I can `checkout remote-name/branch` but I have to > `push remote-name branch` So I can use the same command in svn/cvs to switch branches and publish chang
by pyre 15y ago
> I can `checkout remote-name/branch` but I have to
> `push remote-name branch`
So I can use the same command in svn/cvs to switch branches and publish changes?
> Deleting a local branch is `branch -D` but deleting a
> remote branch is (I still can't fucking believe it)
> `push remote :branch`.
It's not that hard to understand. Most git commands only affect the local repo, but git-push and git-remote are used to affect the remote repo. It makes sense not to break that convention because some people feel it should be organized differently.
In any case, writing to remote repos was never part of the core design of git. It was designed to be a distributed group of people that would pull down remote branches, make changes, and then submit pull requests to the code maintainer (or use the various 'email patch' commands). Remember that it was developed with Linux kernel development in mind, where there is a hierarchy of developers responsible for sections of the codebase.
- phillmv 15y ago>So I can use the same command in svn/cvs to switch branches and publish changes? No, it's about the notation for remotes and branches. It's confusing that sometimes when I refer to a branch I call it remote/branch and other times I call it remote branch. It would've been way more consistent if it were always remote/branch. As a result, git push sometimes gets confusing. Suppose I'm on staging. I then say, git push heroku staging:master (push the staging branch to the master branch on heroku) whereas git push staging:heroku/master is imho easier to understand.
- pyre 15y ago> git push heroku staging:master Without the shortcuts, this command would be: git push heroku refs/heads/staging:refs/heads/master "refs/heads/master" is literally the branch location in the $GIT_DIR on the remote. You could do something like: git push heroku staging:refs/personal/phillmv/staging to stick the branch in a non-standard location, or you could do: git push ssh://hostname/path/to/repo staging:staging or: git push ~pyre/work/repo staging:pillmv-staging to push to a location that you don't have specifically defined as a remote. E.g. % cd /tmp % mkdir test1 test2 % pushd test1 % git init . Initialized empty Git repository in /tmp/test1/.git/ % popd % pushd test2 % git init . Initialized empty Git repository in /tmp/test2/.git/ % git ci --allow-empty -m 'ini commit' [master (root-commit) 54ec2a3] ini commit % git push ../test1 master:test2-master Counting objects: 2, done. Writing objects: 100% (2/2), 168 bytes, done. Total 2 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (2/2), done. To ../test1 * [new branch] master -> test2-master
- phillmv 15y agoHuh. Out of curiosity, why would I ever want to do this? > git push heroku staging:refs/personal/phillmv/staging Will it still appear in git branch lists? I get what you're saying and I appreciate the lesson :). Is there a reason for the syntax in checkout being remote/branchname then? I care about consistency more than the specific syntax.
- pyre 15y ago> Will it still appear in git branch lists? By default, git will only pull branches out of refs/heads/* on the remote repo. You can configure it to do otherwise though. This allows you to store branches on the repo that not everyone will necessarily pull down into their repo. This is obviously less useful with a smaller group of developers and/or a private repository. > Is there a reason for the syntax in checkout > being remote/branchname then? I care about > consistency more than the specific syntax. In git-checkout, you're resolving the branch name locally. When you sync to a remote, a copy of all branches from refs/heads on the remote repo are pulled down and stored in refs/remotes/$remote_name/branch_name. So, refs/heads/master on the remote repo is refs/remotes/origin/master locally. The right side of the ':' in the git-push command resolves on the remote repo, but git-checkout resolves in your local repo. Also look at the git-rev-parse manpage for info on the resolve order/etc for branch name shortcuts. It's the 3rd bullet point under 'Specifying Revisions.'