-
On the command line...
cd
into the lab folder.git init
to initialize the local Git repository. Only do this one time per project!git add .
to add all the files in the project to the staging area. Orgit add <file/folder>
to add a specific file or folder. Include the name or path of the file or folder. Do not include the angle brackets (<, >).git commit -m 'initial commit'
to make the first commit.
-
On GitHub.com, log in and create a new repository. Give it a name, such as "amazing-daisy-lab", and leave all the other options as they are.
-
Copy all lines under "…or push an existing repository from the command line" on GitHub, paste them on the command line, and press ENTER.
-
Refresh the GitHub page to verify that your files have been copied up.
Cloning a repository makes a local repository copy on your computer. Then you can contribute work to that project just like if you had created it yourself (assuming you have permission).
- On GitHub.com, find the repository you want to clone.
- Click the green code button and copy the URL that is shown. The URL starts with "https://github.com" and ends with ".git".
- On the command line,
cd
to a folder where you want this repository on your computer. When you clone it will make a new folder inside of this folder. - Then run this command
git clone PASTE_URL_HERE
, but replace PASTE_URL_HERE with the URL you copied from GitHub. - When the command finishes there should be a new folder with the same name as the GitHub repository.
ls
to see it and/orcd
into it to start working.
On the command line...
git add .
to add all changes in the project to the staging area.git commit -m 'Describe change'
- but replace Describe Change with your own description of the change you're making. Be sure to put the single-quotes around it as in this example.git push
to copy the commit to GitHub.- (optional) Go to GitHub.com and check that your changes are there.
When working with Git, you may run into this screen...
It's a command line program called Vim. You need to know how to exit this program correctly. To do so, type the following keys one-by-one.
ESC
:
(HoldSHIFT
and press the:
key)x
ENTER
Here's what it looks like...
git init
- Initialize (create) a new local repository. Only do this once per project.git add <file/folder>
- Add a file or folder to the staging area. Include the name or path of the file or folder. Do not include the angle brackets (<, >).git commit -m '<message>'
- Commit the staging area changes as a snapshot on the repository timeline. Replace<message>
with a description of the changes you're making. Do not include the angle brackets (<, >).git push
- Push (copy) your committed changes to the remote repositroy (i.e. GitHub).git pull
- Pull (copy) changes from a remote (i.e. GitHub) repository to your computer.git status
- View the current changes and staging areagit diff <file>
- View changes to a file that is unstages.git diff --staged <file>
- View changes to a file that is staged. (What lines were added, removed, and modified?)git log
- View list of commits in the repository snapshot timeline.git show <commit hash>
- View details about a particular commit.git remote -v
- View which remote repository (i.e. GitHub repository) this repo is linked to, if any.git remote add origin <GitHub URL>
- Link to a remote repository (i.e. a GitHub repo).git push -u origin main
- The first push to the remote repository. Sets up for future pushes with simplygit push
.git clone <GitHub URL>
- Download and link a copy of a remote GitHub repository onto your computer. This creates a new folder on your computer.git checkout <commit hash>
- temporarily go back to a commitgit checkout main
- return to the latest commitgit reset --hard <commit hash>
- undo back to an old commitgit push --force
- update GitHub after a resetgit reset --hard origin/main
- reset local repo to GitHubgit checkout -- <file>
- undo all changes to a filegit reset HEAD <file>
- remove a file from staging