Python 3home |
A repository is used to house a codebase.
A codebase refers to the code and supporting files that make up the software projects for a company or for a team, or may refer to a single software project or module, or the code being developed by an individual. A codebase could be developed over the course of years by a number of individuals. A code repository is a program that stores copies of the files in the code base and keeps track of the changes (deltas) that are made to them over time. It is possible to look back to how a given file looked at any previous date, and restore that file to a previous state, as desired. The repository also can manage changes to a code base that may be made by multiple participants -- it then allows those changes to be merged together; in this way it is an excellent collaboration tool. To create a new repository on github.com:
Github creates your project and lands you on the project page, with the name near the top left.
The "secure shell" (ssh) protocol allows us to validate a user, similar to a password.
"ssh keys" refer to a private key + public key arrangement -- the private key is held by the user, and the public key is placed on the server. Only holders of the private key will have access to the account.
Under this encryption scheme, the server can validate this user using the public key, but the public key cannot be used to generate a private key, so it remains secure with the user.
A. Generate a new ssh key pair.
(base) david@192 ~ % ssh-keygen -t ed25519 -C "your_email@example.com"
The ed25519 key type is recommended by github.Your identification has been saved in /Users/david/.ssh/id_ed25519 Your public key has been saved in /Users/david/.ssh/id_ed25519.pub
(base) david@192 ~ % cat /Users/david/.ssh/id_ed25519.pub
C:\Users\david> type C:\Users\david\.ssh\id_ed25519.pub
"Cloning" connects a folder on your local machine to the repo on the server.
A. At the terminal, create a new directory to hold your github repo(s); cd into that directory. 'repos' is a reasonable name; you can also call it something convenient to you.
(base) david@192 ~ % mkdir repos # (where projdir is the name of your repository) (base) david@192 ~ % cd repos (base) david@192 repos %
(base) david@192 repos % git clone git@github.com:davidostest/demo_20230808.git
If this is the first time connecting to git, git responds with the following prompt:
Cloning into 'demo_20230808'...
The authenticity of host 'github.com (140.82.113.4)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Type yes and hit [Enter]. This creates a special .git directory here. You'll see a message to this effect.
(base) david@192 repos % ls demo_20230808 (base) david@192 repos % cd demo_20230808 (base) david@192 demo_20230808 % ls README.md
A "commit" adds a new file or changed file to the repo; "push" syncs the change with the server.
A. Modify the README.md text file to add to the repo. If the file was not created, please create one of this name here. Note the change or the text that you added to this file.
B. Add the new or updated file. Strangely, the add command refers to either newly added or changed files. When we 'add', we're really adding a change to the repo (whether a new or changed file).
(base) david@192 demo_20230808 % git add README.md
(base) david@192 demo_20230808 % git commit -m "first commit"
You'll see a message ackowledging the changes and the commit.
(base) david@192 demo_20230808 % git push -u origin main
You'll see a series of messages indicating a warning (re: adding a RSA host)
This cycle is repeated as we make changes and add these changes to git.
add or change a file (in this case I modified test-1.py)
git status to see that the file has changed
This command shows us the status of all files on our system: modified but not staged, staged but committed and committed but not pushed. (base) david@192 demo_20230808 % git status On branch main Your branch is up-to-date with 'origin/main'. Changes not staged for commit: (use "git add..." to update what will be committed) (use "git checkout -- ..." to discard changes in working directory) modified: test-1.py no changes added to commit (use "git add" and/or "git commit -a") (base) david@192 demo_20230808 %
git add the file (whether added or changed) to the staging area
(base) david@192 demo_20230808 % git add test-1.py
(base) david@192 demo_20230808 %
git status to see that the file has been added
(base) david@192 demo_20230808 % git status On branch main Your branch is up-to-date with 'origin/main'. Changes to be committed: (use "git reset HEAD..." to unstage) modified: test-1.py (base) david@192 demo_20230808 %
git commit the file to the local repository
(base) david@192 demo_20230808 % git commit -m 'made a trivial change'
[main e6309c9] made a trivial change
1 file changed, 4 insertions(+)
(base) david@192 demo_20230808 %
git status to see that the file has been committed, and that our local repository is now "one commit ahead" of the remote repository (known as origin
(base) david@192 demo_20230808 % git status
# On branch main
# Your branch is ahead of 'origin/main' by 1 commit.
#
git pull to pull down any changes that have been made by other contributors
(base) david@192 demo_20230808 % git pull
Already up-to-date.
(base) david@192 demo_20230808 %
git push to push local commit(s) to the remote repo
The remote repo in our case is github.com, although many companies choose to host their own private remote repository.
(base) david@192 demo_20230808 % git push
Counting objects: 11, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 318 bytes | 0 bytes/s, done.
Total 3 (delta 2), reused 0 (delta 0)
To https://github.com/NYU-Python/david-blaikie-solutions
2ce8e49..e6309c9 main -> main
(base) david@192 demo_20230808 %
Once we've pushed changes, we should be able to see the changes on github.com (or our company's private remote repo).