This content is from the fall 2016 version of this course. Please go here for the most recent version.
You only have to do this once per machine.
myrepo
pwd
). cd
to move around. You can clone this repository wherever you want, though eventually you’ll want to develop a system for storing your repos in a consistent manner. Here, I stored mine in /Users/benjamin/Github/
.myrepo
from GitHub to your computer. Cloning simply downloads a copy of the repository to your computer. Remember the URL you copied? It should contain your GitHub username and the name of your practice repository. Either copy + paste the URL into your shell, or if the clipboard doesn’t work retype it manually. Make sure it is accurate.git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY.git
Your output should look like this:
benjamin-laptop:Github benjamin$ git clone https://github.com/bensoltoff/myrepo.git
Cloning into 'myrepo'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
cd myrepo
ls
less README.md # press [q] to quit
git remote show origin
This should look something like:
benjamin-laptop:Github benjamin$ cd myrepo
benjamin-laptop:myrepo benjamin$ ls
README.md
benjamin-laptop:myrepo benjamin$ less README.md
# myrepo
README.md (END)
benjamin-laptop:myrepo benjamin$ git remote show origin
* remote origin
Fetch URL: https://github.com/bensoltoff/myrepo.git
Push URL: https://github.com/bensoltoff/myrepo.git
HEAD branch: master
Remote branch:
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
echo "A line I wrote on my local computer" >> README.md
git status
benjamin-laptop:myrepo benjamin$ echo "A line I wrote on my local computer" >> README.md
benjamin-laptop:myrepo benjamin$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
git add -A
git commit -m "A commit from my local computer"
git push
This should look like:
benjamin-laptop:myrepo benjamin$ git add -A
benjamin-laptop:myrepo benjamin$ git commit -m "A commit from my local computer"
[master 33bb99f] A commit from my local computer
1 file changed, 1 insertion(+), 1 deletion(-)
benjamin-laptop:myrepo benjamin$ git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 294 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/bensoltoff/myrepo.git
d72645a..33bb99f master -> master
If you have never pushed a commit to GitHub, you will be challenged to enter your username and password. Do this.
myrepo
GitHub repository.While the need to authenticate users is obvious (if there was no authentication, anyone could upload changes to your repository), it can be tedious to enter your username and password every time you want to push a change to GitHub. Fortunately there are a couple different options for caching your credentials which we will review here.
Since this was simply a test, there is no need to keep myrepo
. Because we stored the repo on both our computer and GitHub, we need to remove it from both locations.
cd ..
rm -rf myrepo/
This work is licensed under the CC BY-NC 4.0 Creative Commons License.