Вопрос

Can 2 Git clones push/pull to each other without having remote tracking branches representing the other? I know they're very useful most of the time, but I might occasionally want to pull/push between secondary repos (not my bare server), and I don't want to clutter things up. If I don't care about a remote tracking branch, can it be deleted or never created?

Это было полезно?

Решение

If you mean not having a local branch track changes on a remote branch:

You do not have to have your branches track a remote branch. It is a convenience that has a few benefits that you won't have; such as git status stating that your branch is x commits ahead of origin's.

Not setting up a tracking branch does not prevent you from using remotes. Remotes can still be used in all commands instead of typing the URL.

To see what branches are tracked use git branch -avv. Any branches that are tracking a remote branch will list the remote branch to the left of the commit hash.

I don't know a way to remove the tracking from a branch other than to delete it and recreate without tracking.

If you mean the local copy of the remote branch (as seen by git branch -r):

You can delete these with git branch -dr <remote/branch> -- but it will come back next time you pull or fetch it. They are required for git fetch ... to work, and git pull ... uses git fetch .... They would have to be manually deleted each time -- or scripted.

However, they do not add any real clutter or overhead to the repository. The remote tracking branch is, on disk, just a file with a commit hash in it. The commits are saved elsewhere and presumably, since you wanted to fetch them, they have been merged or rebased into one or more local branches.

This information can be fetch using a URL instead of a remote. This does not create a record of what was fetched anywhere but the FETCH_HEAD file. Since this file is overridden with each fetch, the commit data will be lost if not merged or rebased into a local branch before another fetch is performed. The remote tracking branch is there to keep the fetched data from being garbage collected.

Другие советы

Remote tracking branches are not required. They are just a convenience to (a) give git push and pull a default behaviour and (b) to receive information about the local branch status in contrast to the remote one in the git status output. You don’t need either to work with Git.

I don't want to clutter things up

Note that setting up a remote tracking branch does not clutter things at all. All it does is add three lines to the local repositories’ config file. It does not do anything else. All the additional information during git status is only generated when the command is executed; nothing is stored or otherwise cluttering things up. So it’s generally not a problem to have a remote tracking branch set up, even if you don’t need it.

Yes, you can easily achieve that by simply not adding a remote.

The usual way to push/pull between repos is to git remote add NAME URL, but that's just a convenience (and also required for the remote tracking branches).

Instead of using git pull REMOTE_NAME BRANCH, you can just git pull URL BRANCH and use pull in the same fashion. Basically, you can substitute the URL to a repo for a remote's name in most git commands.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top