git clone --single-branch --branch <branchname> <remote-repo>
The --single-branch
option is valid from version 1.7.10 and later.
Please see also the other answer which many people prefer.
You may also want to make sure you understand the difference. And the difference is: by invoking git clone --branch <branchname> url
you’re fetching all the branches and checking out one. That may, for instance, mean that your repository has a 5kB documentation or wiki branch and 5GB data branch. And whenever you want to edit your frontpage, you may end up cloning 5GB of data.
Again, that is not to say git clone --branch
is not the way to accomplish that, it’s just that it’s not always what you want to accomplish, when you’re asking about cloning a specific branch.
Related Posts:
- How do I delete a Git branch locally and remotely?
- How do I delete a Git branch locally and remotely?
- How do I rename a local Git branch?
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- What is the best (and safest) way to merge a Git branch into master?
- How to remove local (untracked) files from the current Git working tree
- Git merge hotfix branch into feature branch
- Git fetch remote branch
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- Git fetch remote branch
- How do I push a new local branch to a remote Git repository and track it too?
- How do I push a new local branch to a remote Git repository and track it too?
- How do I push a new local branch to a remote Git repository and track it too?
- How to get just one file from another branch?
- Update Git branches from master
- Create a branch in Git from another branch
- How do I rename both a Git local and remote branch name?
- Create Git branch with current changes
- How to get the current branch name in Git?
- How do you create a remote Git branch?
- Move the most recent commit(s) to a new branch with Git
- Move the most recent commit(s) to a new branch with Git
- Make an existing Git branch track a remote branch?
- How do I call git diff on the same file between 2 different local branches?
- How to get the current branch name in Git?
- How do you create a remote Git branch?
- Branch from a previous commit using Git
- Clone A Private Repository (Github)
- Not a valid object name: ‘master’
- How to clone a specific Git tag
- How do I copy a version of a single file from one Git branch to another?
- How to clone all remote branches in Git
- Git how to clone with SSH key, username
- Move existing, uncommitted work to a new branch in Git
- How do I clone a single branch in Git?
- Delete branches in Bitbucket
- How do I push a local Git branch to master branch in the remote?
- How to clone git repository with specific revision/changeset?
- How do you clone a Git repository into a specific folder?
- How to keep a branch synchronized/updated with master?
- Git clone verbose output?
- How to get Git to clone into current directory
- How do I run git log to see changes only for a specific branch?
- How to get Git to clone into current directory
- How to create a local branch from an existing remote branch?
- How do I clone a subdirectory only of a Git repository?
- How to find which git branch I am on when my disk is mounted on other server
- How to create a new branch from a tag?
- Git push requires username and password
- Git refusing to merge unrelated histories on rebase
- What is the difference between git push origin and git push origin master
- Git pushing to remote branch
- How to revert a merge commit that’s already pushed to remote branch?
- Git pushing to remote branch
- How do I undo ‘git add’ before commit?
- How can I see the differences between two branches?
- Need to reset git branch to origin version
- What does “Changes not staged for commit” mean
- How can I merge multiple commits onto another branch as a single squashed commit?
- Why does git say “Pull is not possible because you have unmerged files”?
- Pushing empty commits to remote
- How do I ignore an error on ‘git pull’ about my local changes would be overwritten by merge?
- Stash only one file out of multiple files that have changed with Git?
- What is git fast-forwarding? [duplicate]
- fatal: The current branch master has no upstream branch
- How to cherry-pick multiple commits
- Reset local repository branch to be just like remote repository HEAD
- What is “origin” in Git?
- Another git process seems to be running in this repository
- How do you stash an untracked file?
- How to git rebase a branch with the onto command?
- Remove a git commit which has not been pushed
- How can I make Git “forget” about a file that was tracked, but is now in .gitignore?
- How to remove files from git staging area?
- How do I ignore an error on ‘git pull’ about my local changes would be overwritten by merge?
- How to undo git reset –soft to get my changes back?
- .gitignore and “The following untracked working tree files would be overwritten by checkout”
- git – Your branch is ahead of ‘origin/master’ by 1 commit
- git: fatal: Could not read from remote repository
- Git: How to update/checkout a single file from remote origin master?
- Git pull origin
overwrites master? - ERROR: Error cloning remote repo ‘origin’
- Git: Merge a Remote branch locally
- How can I remove a commit on GitHub?
- What is the difference between ‘git remote update’, ‘git fetch’ and ‘git pull’?
- GitLab remote: HTTP Basic: Access denied and fatal Authentication
- What does git push origin HEAD mean?
- What to gitignore from the .idea folder?git intellij-idea gitignore webstorm
- git checkout master error: the following untracked working tree files would be overwritten by checkout
- How can I see the changes in a Git commit?
- Git removing upstream from local repository
- Git pull – Please move or remove them before you can merge
- Unlink of file Failed. Should I try again?
- Resetting remote to a certain commit
- Change the location of the ~ directory in a Windows install of Git Bash
- Git checkout – switching back to HEAD
- Workflow for working with git and WordPress
- best practice on pushing staging development (database/uploads) to the live server
- how can I create a WP offline environment before releasing the websites? [closed]