git
commands to be run in TERMINAL: Make sure you are not running them from the R CONSOLE!error: cannot run rpostback-askpass: No such file or directory
. Ignore it and do what you’re doing!git
commands can be run from anywhere INSIDE the git repository - doesn’t matter which specific directory (doesn’t need to be “top level”) as long as you are in one of them.git pusj
misspelling git push
), git
will try to suggest to you which command you actually want! It’s very helpful.git
is a software that performs version control (specifically, “distributed version control.”) github.com
is a website that you can use with git
gitlab.com
and bitbucket.org
, but github.com
is probably the most popular.git
is managinggit
knows about are tracked, i.e they are under version controlgit
it should track the file and stage it for the next commitgit
the file has been modified and we want to stage it (prepare for commit)github.com
remote of the repositorygithub.com
repository to the local clonegit
and github.com
for the first time with a given computerThese commands should be typed into Terminal. This tells git
about the identity of the “person working with git
on this computer.”
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
For example, I would type:
git config --global user.email "spielman@rowan.edu"
git config --global user.name "Stephanie Spielman"
github.com
who your computer isThese commands should be typed in R Console, making use of the handy credentials
R package. You can also accomplish this with different commands in the Terminal, but this is much less irritating, I promise.
First, enter the following into the R Console in RStudio Cloud. We’ll need its output:
# Generate an SSH Key to pair with GitHub
credentials::ssh_keygen()
Then…
$pubkey
, excluding the quotes.git
command referenceCommand | Description |
---|---|
git clone <ssh repo address> |
Clone the repository to a new computer. This should only be run ONCE. This like like downloading the repository. |
git add filename |
Stage a file with changes. Use this to tell git: There are changes here you should know about. |
git commit -m "message" |
Commit files that have been added/removed with a message! Don’t forget to type the -m "message" - you will be stuck in VIM if you forget, and that will not be pleasant. |
git push |
Send commit(s) to github.com |
git pull |
Obtain commits pushed to github.com onto the current machine. When working on multiple computers or with contributors, you should do this EVERY TIME you start working again in the project. |
git mv old_filename new_filename |
Move a file and track this move with git in a shortcut version of mv old_filename new_filename; git add new_filename (Note: there is no analogous shortcut for cp ). Use this to mv files that git knows about! |
git rm filename |
Remove a file from being tracked by git entirely. Hopefully you won’t have to do this :). |
git status |
Check the status of files. |
git checkout filename |
Obtain the most recent commited version of the file. Use this if you screwed something up and need to “reset” to the last COMMITTED version. It’s like an “Undo” button! |
git log |
See past commits and associated messages (may need to press the q key to exit) |
git
workflowAt any and all times, running
git status
will show you what is staged, what is tracked but not staged, and what is not tracked at all.
git clone <repo ssh address>
cd
to navigate into that repository’s directory in the terminal.git add <filename>
git rm <filename>
. You probably won’t need this for your project.git mv <original> <new>
git commit -m "An informative message that broadly says what the commit does"
-m
, you’re going to have a very bad time. Like, BAD.github.com
repository versions with git push
github.com
username and password every time.github.com
version of the repository with git pull
git status
On branch main
Your branch is up to date with 'origin/main'.
nothing to commit, working tree clean
git
doesn’t know about the files yet.On branch main
Your branch is up to date with 'origin/main'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
new_file.txt
nothing added to commit but untracked files present (use "git add" to track)
On branch main
Your branch is up to date with 'origin/main'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: new_file.txt
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
Some messages you might see, what they mean, and how to deal with them:
#### When running pretty much any git command:
fatal: not a git repository (or any of the parent directories): .git
This means you are running git commands but you are not in a git repository! You have to cd
into the a repository’s directory to run git commands.
fatal: pathspec <name of file> did not match any files
This means you are trying to add or remove a file that doesn’t exist! Potentially, the file isn’t there at all - (did you spell it wrong? are you in right directory? However, if the file does exist and you can’t git rm
it, that’s because the file isn’t actually under version control! git
doesn’t already know about the file so it doesn’t want to remove it. Instead, you need to just remove the file regularly with plain rm
instead of git rm
.
commit
error: switch `m' requires a value
You forgot the commit message! You can’t just type git commit -m
- you need git commit -m "YOUR MESSAGE GOES HERE"
.