-
Notifications
You must be signed in to change notification settings - Fork 336
/
git-commands.Rmd
99 lines (71 loc) · 1.77 KB
/
git-commands.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Git commands {#git-commands}
A collection of some of the Git commands that have been largely going on under the hood.
We've emphasized early workflows that are possible in RStudio.
But all of this and much more can be done from the command line.
This list is here mostly so we can consult it during live workshops if needed.
*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:
```console
git clone https://github.com/jennybc/happy-git-with-r.git
```
Check the remote was cloned successfully:
```console
git remote --verbose
```
Stage local changes, commit:
```console
git add foo.txt
git commit --message "A commit message"
```
Check on the state of the Git world:
```console
git status
git log
git log --oneline
```
Compare versions:
```console
git diff
```
Add a remote to existing local repo:
```console
git remote add origin https://github.com/jennybc/happy-git-with-r
git remote --verbose
git remote show origin
```
Push local `main` to GitHub `main` and have local `main` track `main` on GitHub:
```console
git push --set-upstream origin main
# shorter form
git push -u origin main
# you only need to set upstream tracking once!
```
Regular push:
```console
git push
# the above usually implies (and certainly does in our tutorial)
git push origin main
# git push [remote-name] [branch-name]
```
Pull commits from GitHub:
```console
git pull
```
Pull commits and don't let it put you in a merge conflict pickle:
```console
git pull --ff-only
```
Fetch commits
```console
git fetch
```
Switch to a branch
```console
git checkout [branch-name]
```
Checking remote and branch tracking
```console
git remote -v
git remote show origin
git branch -vv
```