A Short History of Git
Linux kernel is an open source software project of large scope.
Maintenance changes to the software were patches.
In 2002, the project began using a DVCS called BitKeeper.
In 2005, the development community developed their own tool.
The development of the GitHub platform began on October 19, 2007.
Some of the goals of the new system were as follows:
Speed
Simple design
Strong support for non-linear development (thousands of parallel branches)
Fully distributed
Able to handle large projects like the Linux kernel efficiently
Git easy to use, fast and efficient with large projects,
has a branching system for non-linear development.
What is Git?
Git is a distributed version-control system for tracking changes in code
during software development.
A GitHub repository is a storage space where your project's files are in one centralized location, allowing you to manage and share code with collaborators.
Designed for coordinating work among programmers, but it can be used to track changes in any set of files.
Speed, data integrity, and support for distributed,non-linear workflows
Issue tracking
Decentralized / distributed - can be centralized
Awesome scale used for the million lines of the Linux Kernal.
fast-version-control
What is GitHub?
GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere.
GitHub essentials like repositories, branches, commits, and Pull Requests. GitHub’s Pull Request workflow, a popular way to create and review code.
What is a Git repository?
Git is a program that tracks changes made to files.
Can be initialized on a project to create a Git repository.
A Git repository is the .git/ folder inside a project.
This repository tracks all changes made to files in your project, building a history over time.
Meaning, if you delete the .git/ folder, then you delete your project’s history.
Git Basics - Getting a Git Repository
Getting a Git Repository
Obtain a Git repository in one of two ways:
Take a local directory and turn it into a Git repository, or
You can clone an existing Git repository from elsewhere.
Git repository on your local machine, ready for work.
Initializing a Repository in an Existing Directory
Project directory and you want to start controlling it with Git,
first need to go to that project’s directory.
for Linux:
$ cd /home/user/my_project
$ git init
The three stages of Git
Files in a repository go through three stages before being under version control with git:
Untracked: the file exists, but is not part of git's version control.
Staged: the file has been added to git's version control but changes have not been committed.
Committed: the change has been committed.
Create new project for python invoicer - python inv
project in this session is set to python-inv
Git-status is used to understand what stage the files in a repository are at.
“gcloud config set project [PROJECT_ID]” to change to a different project.
Debian/Ubuntu
For the latest stable version for your release of Debian/Ubuntu
Note: need to use sudo for super user access to install
# sudo apt-get install git
Make a directory for your projects
admin_@cloudshell:~ (python-inv)$ mkdir python-inv
admin_@cloudshell:~ (python-inv)$
Use git init to create a git repository
admin_@cloudshell:~ (python-inv)$ git init python-inv
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /home/admin_/python-inv/.git/
Check the state of the working directory and the staging area.
admin_@cloudshell:~/python-inv (python-inv)$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
CREATE a README.md file
Markdown(.md) is a lightweight markup language with plain-text-formatting syntax, created in 2004 by John Gruber with Aaron Swartz.
Markdown is often used for formatting readme files, for writing messages in online discussion forums, and to create rich text using a plain text editor.
Create a README.md file in the directory using your text editor
# python-inv project
This is a sample README.md file
Python invoicer will produce an invoice on products sold
admin_@cloudshell:~/python-inv (python-inv)$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
Add README.md to in the working directory to the staging
admin_@cloudshell:~/python-inv (python-inv)$ git add README.md
admin_@cloudshell:~/python-inv (python-inv)$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
Git commit is used to save your changes to the local repository
admin_@cloudshell:~/python-inv (python-inv)$ git config --global user.email "admin@uconnstamforddsc.org"
admin_@cloudshell:~/python-inv (python-inv)$ git config --global user.name "UCONN Administrator"
admin_@cloudshell:~/python-inv (python-inv)$ git commit -m "First file in python-inv repository"
[master (root-commit) b48f504] First file in python-inv repository
1 file changed, 5 insertions(+)
create mode 100644 README.md
admin_@cloudshell:~/python-inv (python-inv)$ git status
On branch master
nothing to commit, working tree clean
admin_@cloudshell:~/python-inv (python-inv)$ ls -al
total 16
drwxr-xr-x 3 admin_ admin_ 4096 Sep 16 17:22 .
drwxr-xr-x 37 admin_ admin_ 4096 Sep 16 17:38 ..
drwxr-xr-x 8 admin_ admin_ 4096 Sep 16 17:41 .git
-rw-r--r-- 1 admin_ admin_ 111 Sep 16 17:22 README.md
Change into the .git directory to look at files (managed by git do not change)
admin_@cloudshell:~/python-inv (python-inv)$ cd .git
admin_@cloudshell:~/python-inv/.git (python-inv)$ ls -al
total 52
drwxr-xr-x 8 admin_ admin_ 4096 Sep 16 17:41 .
drwxr-xr-x 3 admin_ admin_ 4096 Sep 16 17:22 ..
drwxr-xr-x 2 admin_ admin_ 4096 Sep 16 17:08 branches
-rw-r--r-- 1 admin_ admin_ 36 Sep 16 17:39 COMMIT_EDITMSG
-rw-r--r-- 1 admin_ admin_ 67 Sep 16 17:08 config
-rw-r--r-- 1 admin_ admin_ 73 Sep 16 17:08 description
-rw-r--r-- 1 admin_ admin_ 23 Sep 16 17:08 HEAD
drwxr-xr-x 2 admin_ admin_ 4096 Sep 16 17:08 hooks
-rw-r--r-- 1 admin_ admin_ 137 Sep 16 17:33 index
drwxr-xr-x 2 admin_ admin_ 4096 Sep 16 17:08 info
drwxr-xr-x 3 admin_ admin_ 4096 Sep 16 17:39 logs
drwxr-xr-x 7 admin_ admin_ 4096 Sep 16 17:39 objects
drwxr-xr-x 4 admin_ admin_ 4096 Sep 16 17:08 refs
Check the repository using git log A Git log is a running record of commits.
admin_@cloudshell:~/python-inv/.git (python-inv)$ cd ..
admin_@cloudshell:~/python-inv (python-inv)$ git log
commit b48f504400ed3373b2f4a898902a6fa9f40df0cc (HEAD -> master)
Author: UCONN Administrator <admin@uconnstamforddsc.org>
Date: Sat Sep 16 17:39:03 2023 +0000
First file in python-inv repositor
Now we can edit the README.md file
# python-inv project
This is a sample README.md file
Python invoicer will produce an invoice on products sold
Collects customer information and displays inventory
admin_@cloudshell:~/python-inv (python-inv)$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
Add new file to repository
admin_@cloudshell:~/python-inv (python-inv)$ touch newfile.txt
admin_@cloudshell:~/python-inv (python-inv)$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
Untracked files:
(use "git add <file>..." to include in what will be committed)
newfile.txt
no changes added to commit (use "git add" and/or "git commit -a")
john_iacovacci1@cloudshell:~/pyprojects/py-invoicer (hello-uconn)$ git ls-files
README.md
Create account on github.com
Create new repository
Create new repository called python-inv
Generate a personal access code
Click on user icon in upper right hand corner
Click into setting
Lower left hand corner click into developer settings
Then Personal access tokens
Tokens (classic)
Generate new token
Give it a name and check repo box
Then click green Generate token Button
Copy Token
Use token when linux prompts you for github password for your account
Push or pull repository
https://github.com/uconnstamford/python-inv.git
…or create a new repository on the command line
echo "# python-inv" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/uconnstamford/python-inv.git
git push -u origin main
…or push an existing repository from the command line
git remote add origin https://github.com/uconnstamford/python-inv.git
git branch -M main
git push -u origin main
Back to Cloud Shell
Setup for remote
admin_@cloudshell:~/python-inv (python-inv)$ git remote -v
origin https://github.com/uconnstamford/python-inv.git (fetch)
origin https://github.com/uconnstamford/python-inv.git (push)
admin_@cloudshell:~/python-inv (python-inv)$ git remote add origin https://github.com/uconnstamford/python-inv.git
Push to remote
admin_@cloudshell:~/python-inv (python-inv)$ git push -u origin main
Username for 'https://github.com': admin@uconnstamforddsc.org
Password for 'https://admin@uconnstamforddsc.org@github.com':
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 4 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 336 bytes | 336.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/uconnstamford/python-inv.git
* [new branch] main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.
Files now appear on Github
To get files from another user account
Use the git clone command to create a copy of a specific repository or branch within a repository
Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to uconn-engr.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
john_iacovacci1@cloudshell:~ (uconn-engr)$ git clone https://github.com/uconnstamford/python-inv.git
Cloning into 'python-inv'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 3 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
john_iacovacci1@cloudshell:~ (uconn-engr)$
My project files are now in the python-inv directory
john_iacovacci1@cloudshell:~ (uconn-engr)$ cd python-inv
john_iacovacci1@cloudshell:~/python-inv (uconn-engr)$ ls -al
total 16
drwxr-xr-x 3 john_iacovacci1 john_iacovacci1 4096 Sep 17 15:24 .
drwxr-xr-x 52 john_iacovacci1 john_iacovacci1 4096 Sep 17 15:24 ..
drwxr-xr-x 8 john_iacovacci1 john_iacovacci1 4096 Sep 17 15:24 .git
-rw-r--r-- 1 john_iacovacci1 john_iacovacci1 111 Sep 17 15:24 README.md
GitHub Tutorial: This will serve as a quick user guide to using a GitHub repository.
A GitHub repository is a storage space where your project's files are in one centralized location, allowing you to manage and share code with collaborators.
The following are the essential git commands you must know to be able to utilize a repository:
git init: create a repository in the current directory
git clone : downloads a repository from an outside source onto your machine
git add : stages changes to be made, specific file
git add .: stages changes to be made, everything
git commit -m "Message": Record changes made
git push origin : moves your changes onto a branch in the repo, main is the default
git pull origin : merges changes made to the branch into your current workspace, main for default
No comments:
Post a Comment