Skip to content

Commit

Permalink
start to list relevant git commands
Browse files Browse the repository at this point in the history
  • Loading branch information
jennybc committed Jun 27, 2016
1 parent eea4147 commit e9de147
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
94 changes: 94 additions & 0 deletions 38_usage-git-commands.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# Git commands {#usage-git-cmds}

Here's a start on the various Git commands that have been largely going on under the hood. We've tried to pick workflows that have RStudio doing this for us. But all of this can be done from the command line.

*Unless you use the [GitHub API](https://developer.github.com/v3/), most of the GitHub bits really have to be done from the browser.*

New local git repo from a repo on GitHub:

``` bash
git clone https://github.com/jennybc/happy-git-with-r.git
```

Check the remote was cloned successfully:

``` bash
git remote --verbose
```

Stage local changes, commit:

``` bash
git add foo.txt
git commit --message "A commit message"
```

Check on the state of the Git world:

``` bash
git status
git log
```

Compare versions:

``` bash
git diff
```

Add a remote to existing local repo:

``` bash
git remote add origin https://github.com/jennybc/happy-git-with-r
git remote --verbose
git remote show origin
```

Push local master to GitHub master and have local master track master on GitHub:

``` bash
git push --set-upstream origin master
## shorter form
git push -u origin master
## you only need to set upstream tracking once!
```

Regular push:

``` bash
git push
## the above usually implies (and certainly does in our tutorial)
git push origin master
## git push [remote-name] [branch-name]
```

Pull commits from GitHub:

``` bash
git pull
```

Pull commits and don't let it put you in a merge conflict pickle:

``` bash
git pull --ff-only
```

Fetch commits

``` bash
git fetch
```

Switch to a branch

``` bash
git checkout [branch-name]
```

Checking remote and branch tracking

``` bash
git remote -v
git branch -vv
```
4 changes: 4 additions & 0 deletions 50_more-content.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Notes for future

## Common workflow questions

### Common predicaments and how to recover/avoid

https://twitter.com/JennyBryan/status/743457387730735104

### Keep something out of Git

List it in `.gitignore.`
Expand Down
1 change: 1 addition & 0 deletions _bookdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ rmd_files: [

"30_usage-first-use-rmd-and-github.Rmd",
"31_usage-first-use-r-script-and-github.Rmd",
"38_usage-git-commands.Rmd",

"40_prompt-clone.Rmd",
"41_prompt-fork.Rmd",
Expand Down

0 comments on commit e9de147

Please sign in to comment.