Предположим, у вас есть загруженный из центрального репозитория бранч:
d:Temp>git clone https://bitbucket.org/username/testrepo Cloning into 'testrepo'... Username for 'https://bitbucket.org': username Password for 'https://[email protected]': remote: Counting objects: 3, done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. Checking connectivity... done.
В котором вы создаёте новый бранч:
d:Temp>cd testrepo d:Temptestrepo>git checkout -b newbranch Switched to a new branch 'newbranch'
d:Temptestrepo>git branch master * newbranch
Добавляете в него файл:
d:Temptestrepo>echo "sometext" > newbranchfile.txt d:Temptestrepo>type newbranchfile.txt "sometext" d:Temptestrepo>git status On branch newbranch Untracked files: (use "git add <file>..." to include in what will be committed) newbranchfile.txt nothing added to commit but untracked files present (use "git add" to track) d:Temptestrepo>git add newbranchfile.txt d:Temptestrepo>git commit -m "Added new file" [newbranch 1793d24] Added new file 1 file changed, 1 insertion(+) create mode 100644 newbranchfile.txt
Теперь, что бы загрузить новый бранч с новым файлом – используйте git push
с опцией -u
:
d:Temptestrepo>git push -u origin newbranch Username for 'https://bitbucket.org': username Password for 'https://[email protected]': ... To https://bitbucket.org/username/testrepo * [new branch] newbranch -> newbranch Branch newbranch set up to track remote branch newbranch from origin.
Проверяем удалённый репозиторий:
d:Temptestrepo>git ls-remote Username for 'https://bitbucket.org': username Password for 'https://[email protected]': From https://bitbucket.org/username/testrepo 207d8051fd2685652251a1de2236059fb8f57e18 HEAD 207d8051fd2685652251a1de2236059fb8f57e18 refs/heads/master 1793d2437520c5714ac27bd41073da9bcbf1789b refs/heads/newbranch
Проверяем файлы в разных бранчах:
d:Temptestrepo>git ls-tree -r --name-only newbranch file.txt newbranchfile.txt d:Temptestrepo>git ls-tree -r --name-only master file.txt
Готово.