09. Remote
The git remote
command lets you create, view, and delete connections to other repositories. Remote connections are more like bookmarks rather than direct links into other repositories. Instead of providing real-time access to another repository, they serve as convenient names that can be used to reference a not-so-convenient URL.
origin
remote
origin
remoteorigin
– это произвольное имя (можно поменять) удаленного репозитория, с которым связан текущий. Кстати, таких удаленных репозиториев может быть сколько угодно. На практике такое поведение действительно бывает нужно, когда изменения отправляются сразу в несколько мест.
По умолчанию она идет в удаленный репозиторий origin
и пушит текущую ветку, при условии что установлен "трекинг".
Трекинг – это отслеживание удаленного репозитория. Крайне важно понимать, что одинаковые названия веток в разных репозиториях для гита ничего не значат. Каждой ветки нужно установить соответствие (когда вы делаете git push
, гит сам предложит команду, выполнив которую установится трекинг). Понятно, что на практике название веток почти всегда совпадают.
Если вы хотите отправлять текущую ветку в другой репозиторий или другую ветку, то можно сделать так:
Remote branch
Remote branches are just like local branches, except they represent commits from somebody else repository. You can check out a remote branch just like a local one, but this puts you in a detached HEAD state (just like checking out an old commit). You can think of them as read-only branches. Again, you can inspect these branches with the usual git checkout
and git log
commands.
Synchronize with remote repository
Fetching changes
The git fetch
command imports commits from a remote repository into your local repo. The resulting commits are stored as remote branches instead of the normal local branches that we’ve been working with. Since fetched content is represented as a remote branch, it has absolutely no effect on your local development work. This gives you a chance to review changes before integrating them into your copy of the project.
Pulling changes
Merging upstream changes into your local repository is a common task in Git-based collaboration workflows. git pull <remote>
is a alias for git fetch <remote>
and git merge origin/<current-branch>
executing one after each other.
Pushing changes
Pushing is how you transfer commits from your local repository to a remote repo. It's the counterpart to git fetch, but whereas fetching imports commits to local branches, pushing exports commits to remote branches.
git push <remote> <branch>
- работает при условии, что у вас есть права на запись и не было добавлено новых коммитов. This creates a local branch in the destination repository.
Last updated
Was this helpful?