- Let's set up our new repository to only fetch the master branch. We do this by changing the fetch line under [remote "origin"] in the configuration file (.git/config), as follows:
[remote "origin"] url = ../jgit-bare.git fetch = +refs/heads/master:refs/remotes/origin/master
- Now, we will only fetch the master branch and not all the other branches when executing a git fetch, git pull, or a git remote update origin, as follows:
$ git pull remote: Counting objects: 44033, done. remote: Compressing objects: 100% (6927/6927), done. remote: Total 44033 (delta 24063), reused 44033 (delta 24063) Receiving objects: 100% (44033/44033), 9.45 MiB | 5.70 MiB/s, done. Resolving deltas: 100% (24063/24063), done. From ../jgit-bare * [new branch] master -> origin/master From ../jgit-bare * [new tag] v0.10.1 -> v0.10.1 * [new tag] v0.11.1 -> v0.11.1 * [new tag] v0.11.3 -> v0.11.3 ... $ git branch -a * master remotes/origin/master
- Let's also set up a separate refspec to fetch all the stable/* branches to the local repository as follows:
[remote "origin"] url = ../jgit-bare.git fetch = +refs/heads/master:refs/remotes/origin/master fetch = +refs/heads/stable/*:refs/remotes/origin/stable/*
- Now, fetch the branches locally, as shown in the following command:
$ git fetch From ../jgit-bare * [new branch] stable/0.10 -> origin/stable/0.10 * [new branch] stable/0.11 -> origin/stable/0.11 * [new branch] stable/0.12 -> origin/stable/0.12 * [new branch] stable/0.7 -> origin/stable/0.7 * [new branch] stable/0.8 -> origin/stable/0.8 * [new branch] stable/0.9 -> origin/stable/0.9 * [new branch] stable/1.0 -> origin/stable/1.0 * [new branch] stable/1.1 -> origin/stable/1.1 * [new branch] stable/1.2 -> origin/stable/1.2 * [new branch] stable/1.3 -> origin/stable/1.3 * [new branch] stable/2.0 -> origin/stable/2.0 * [new branch] stable/2.1 -> origin/stable/2.1 * [new branch] stable/2.2 -> origin/stable/2.2 * [new branch] stable/2.3 -> origin/stable/2.3 * [new branch] stable/3.0 -> origin/stable/3.0 * [new branch] stable/3.1 -> origin/stable/3.1 * [new branch] stable/3.2 -> origin/stable/3.2
- We can also set up a push refspec that specifies where branches are pushed to by default. Let's create a branch called develop and create one commit, as shown in the following commands:
$ git checkout -b develop Switched to a new branch 'develop' $ echo "This is the developer setup, read carefully" > readme-dev.txt $ git add readme-dev.txt
$ git commit -m "adds readme file for developers" [develop ccb2f08] adds readme file for developers 1 file changed, 1 insertion(+) create mode 100644 readme-dev.txt
- Now, let's create a push refspec that will send the content of the develop branch to integration/master on origin:
[remote "origin"] url = ../jgit-bare.git fetch = +refs/heads/master:refs/remotes/origin/master fetch = +refs/heads/stable/*:refs/remotes/origin/stable/* push = refs/heads/develop:refs/remotes/origin/integration/master
- Let's push our commit on develop as follows:
$ git push Counting objects: 4, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 345 bytes | 0 bytes/s, done. Total 3 (delta 1), reused 0 (delta 0) To ../jgit-bare.git * [new branch] develop -> origin/integration/master
As the integration/master branch didn't exist on the remote side, it was created for us.