Description Usage Arguments Details git_switch git_branch_checkout Examples
Switch to or "checkout" another branch. Optionally, create the branch if it doesn't exist yet and then check it out.
1 2 3 4 |
name |
Name of the branch |
create |
Whether to create the branch if it does not exist yet |
repo |
Path to a Git repo. If unspecified, current working directory is checked to see if it is or is inside a Git repo. |
rev |
Target commit, as a
revision
string, e.g. |
force |
Whether to overwrite current files with the versions in branch
|
If you currently have uncommitted changes, it is possible – though not
inevitable – to lose those changes when you switch to another branch.
git_switch()
will never let that happen. You should seriously consider
committing or stashing those at-risk changes. However, if you really want to
nuke them, call the lower-level function git_branch_checkout(..., force
= TRUE)
.
Convenience wrappers around git2r
's
checkout,git_branch-method
.
Designed for interactive use. Request a branch by name
or, by
default, switch to master
. If the branch doesn't exist yet, you'll
get an offer to create it and immediately check it out.
git_switch()
will not let you switch branches if you have
uncommitted changes that would be lost. You should either:
Commit or stash these changes. Then call git_switch()
again.
Use git_branch_checkout()
directly, with force = TRUE
,
if you are willing to lose these changes.
Designed for non-interactive use. If the branch doesn't exist yet, you'll
have to explicitly authorize its creation via create = TRUE
.
force = TRUE
will checkout branch name
even if it means
losing uncommitted changes. In the future, githug will make a branch and a
commit or a stash behind the scenes here, in case you later have regrets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | repo <- git_init(tempfile("githug-branches-"))
owd <- setwd(repo)
## first commit
writeLines("Well, we're not in the middle of nowhere...", "nowhere.txt")
git_commit("nowhere.txt", message = "1: not in the middle of nowhere")
git_branch_list()
## Not run:
## in an interactive session, try this to checkout and create at once
git_switch("louise")
## End(Not run)
git_branch_checkout("louise", create = TRUE)
git_branch_current()
setwd(owd)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.