What is Git?
Git is a distributed version-control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows
Issue tracking
Decentralized / distributed - can be centralized
Awesome scale used for 15 million lines of Linux Kernal.
Git was created by Linus Torvalds in 2005 for development of the Linux kernel, with other kernel developers contributing to its initial development.
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 (speed and data size)
--fast-version-control
What is a Git repository?
Git is a program that tracks changes made to files. Once installed, Git 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.
2.1 Git Basics - Getting a Git Repository
If you can read only one chapter to get going with Git, this is it. This chapter covers every basic command you need to do the vast majority of the things you’ll eventually spend your time doing with Git. By the end of the chapter, you should be able to configure and initialize a repository, begin and stop tracking files, and stage and commit changes. We’ll also show you how to set up Git to ignore certain files and file patterns, how to undo mistakes quickly and easily, how to browse the history of your project and view changes between commits, and how to push and pull from remote repositories.
Getting a Git Repository
You typically obtain a Git repository in one of two ways:
You can take a local directory that is currently not under version control, and turn it into a Git repository, or
You can clone an existing Git repository from elsewhere.
In either case, you end up with a Git repository on your local machine, ready for work.
Initializing a Repository in an Existing Directory
If you have a project directory that is currently not under version control and you want to start controlling it with Git, you first need to go to that project’s directory. If you’ve never done this, it looks a little different depending on which system you’re running:
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
Git-status is used to understand what stage the files in a repository are at.
project in this session is set to uconn-engr.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
Make a directory for your projects
john_iacovacci1@cloudshell:~ (uconn-engr)$ mkdir pyprojects
Use git init to create a git repository
john_iacovacci1@cloudshell:~ (uconn-engr)$ git init assign4
Initialized empty Git repository in /home/john_iacovacci1/assign4/.git/
john_iacovacci1@cloudshell:~ (uconn-engr)$
Check your files
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ ls -al
total 12
drwxr-xr-x 3 john_iacovacci1 john_iacovacci1 4096 Oct 4 00:53 .
drwxr-xr-x 3 john_iacovacci1 john_iacovacci1 4096 Oct 4 00:53 ..
drwxr-xr-x 7 john_iacovacci1 john_iacovacci1 4096 Oct 4 00:53 .git
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$
Check the state of the working directory and the staging area.
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git status
On branch master
No commits yet
nothing to commit (create/copy files and use "git add" to track)
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$
CREATE a README.md file
Markdown 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
Check Status
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ 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)
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$
Add README.md to in the working directory to the staging
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git add README.md
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$
Places file in git staging area
Git commit is used to save your changes to the local repository
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git commit -m "First file in assign4 repo"
[master (root-commit) bc57311] First file in assign4 repo
1 file changed, 3 insertions(+)
create mode 100644 README.md
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$
Root commit
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git status
On branch master
nothing to commit, working tree clean
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$
One committed file
total 16
drwxr-xr-x 3 john_iacovacci1 john_iacovacci1 4096 Oct 4 01:10 .
drwxr-xr-x 3 john_iacovacci1 john_iacovacci1 4096 Oct 4 00:53 ..
drwxr-xr-x 8 john_iacovacci1 john_iacovacci1 4096 Oct 4 01:52 .git
-rw-r--r-- 1 john_iacovacci1 rvm 48 Oct 4 01:24 README.md
Change into the .git directory to look at files (managed by git do not change)
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ cd .git
john_iacovacci1@cloudshell:~/pyprojects/assign4/.git (uconn-engr)$ ls -al
total 52
drwxr-xr-x 8 john_iacovacci1 john_iacovacci1 4096 Oct 4 01:52 .
drwxr-xr-x 3 john_iacovacci1 john_iacovacci1 4096 Oct 4 01:10 ..
drwxr-xr-x 2 john_iacovacci1 john_iacovacci1 4096 Oct 4 00:53 branches
-rw-r--r-- 1 john_iacovacci1 john_iacovacci1 27 Oct 4 01:33 COMMIT_EDITMSG
-rw-r--r-- 1 john_iacovacci1 john_iacovacci1 67 Oct 4 00:53 config
-rw-r--r-- 1 john_iacovacci1 john_iacovacci1 73 Oct 4 00:53 description
-rw-r--r-- 1 john_iacovacci1 john_iacovacci1 23 Oct 4 00:53 HEAD
drwxr-xr-x 2 john_iacovacci1 john_iacovacci1 4096 Oct 4 00:53 hooks
-rw-r--r-- 1 john_iacovacci1 john_iacovacci1 137 Oct 4 01:33 index
drwxr-xr-x 2 john_iacovacci1 john_iacovacci1 4096 Oct 4 00:53 info
drwxr-xr-x 3 john_iacovacci1 john_iacovacci1 4096 Oct 4 01:33 logs
drwxr-xr-x 7 john_iacovacci1 john_iacovacci1 4096 Oct 4 01:33 objects
drwxr-xr-x 4 john_iacovacci1 john_iacovacci1 4096 Oct 4 00:53 refs
john_iacovacci1@cloudshell:~/pyprojects/assign4/.git (uconn-engr)$
Check the repository using git log A Git log is a running record of commits.
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git log
commit bc573113f48a0c3222dffd68b06624d55e629a9a (HEAD -> master)
Author: John Iacovacci <john.iacovacci1@gmail.com>
Date: Sun Oct 4 01:33:34 2020 +0000
First file in assign4 repo
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$
Edit README.md
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git status
On branch 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")
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ touch newfile.txt
Check status
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git status
On branch 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
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/assign4 (uconn-engr)$
Use git ls-files to see what git is tracking
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git ls-files
README.md
Create account on github
Create new repository
Push or pull repository
Back to Cloud Shell
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git remote -v
No remotes are set up
Setup for remote
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git remote add origin https://github.com/jiacovacci/assign4.git
Check setup
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git remote -v
origin https://github.com/jiacovacci/assign4.git (fetch)
origin https://github.com/jiacovacci/assign4.git (push)
Push to remote
john_iacovacci1@cloudshell:~/pyprojects/assign4 (uconn-engr)$ git push -u origin master --tags
Username for 'https://github.com': john.iacovacci1@gmail.com
Password for 'https://john.iacovacci1@gmail.com@github.com':password
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 2 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (6/6), 579 bytes | 193.00 KiB/s, done.
Total 6 (delta 0), reused 0 (delta 0)
To https://github.com/jiacovacci/assign4.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
Files now appear on Github
To get files from another user account
Welcome to Cloud Shell! Type "help" to get started.
Your Cloud Platform project in this session is set to my-email-api-tor.
Use “gcloud config set project [PROJECT_ID]” to change to a different project.
john@cloudshell:~ (my-email-api-tor)$ git clone https://github.com/jiacovacci/assign4.git
Cloning into 'assign4'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.
john@cloudshell:~ (my-email-api-tor)$
My project files are now in the assign4 directory
john@cloudshell:~ (my-email-api-tor)$ cd assign4
john@cloudshell:~/assign4 (my-email-api-tor)$ ls
README.md
john@cloudshell:~/assign4 (my-email-api-tor)$
Link to Cloud Source Repository Quickstart
Cloud Source Repositories are private Git repositories hosted on Google Cloud. These repositories let you develop and deploy an app or service in a space that provides collaboration and version control for your cod
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.
This tutorial teaches you GitHub essentials like repositories, branches, commits, and Pull Requests. You’ll create your own Hello World repository and learn GitHub’s Pull Request workflow, a popular way to create and review code.
$ sudo apt install git-all
$ git --version
git version 2.11.0
Create a repository
In a terminal window, use the gcloud source repos create command to create a Google Cloud repository named hello-world:
gcloud source repos create hello-world
Created [hello-world].
Clone a repository
Use the gcloud source repos clone command to clone the contents of the Google Cloud repository into a local Git repository:
$ gcloud source repos clone hello-world
Cloning into '/home/john_iacovacci1/hello-world'...
warning: You appear to have cloned an empty repository.
Project [uconn-engr] repository [hello-world] was clone
d to [/home/john_iacovacci1/hello-world].
Create a "Hello, World!" script
Create a Python script that prints Hello, World! in a browser window.
Go to your hello-world repository.
Using a text editor, create a file named main.py, and then paste the following code:
#!/usr/bin/env python
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.write('Hello, World!')
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
Create an app.yaml file
Create an app.yaml file that contains the configuration information you need to deploy your code to App Engine.
Go to your hello-world repository.
Using a text editor, create a file named app.yaml, and then paste the following configuration information:
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
Push to Cloud Source Repositories
Push the files you just created into Cloud Source Repositories.
In a terminal window, go to your hello-world directory
$ cd hello-world
Add the files:
$ git add .
Config repository for email and name
$ git config --global user.email "john.iacovacci1@gm
ail.com"
$ git config --global user.name "John Iacovacci"
Commit the files to the repository with a comment describing the history of this action:
$ git commit -m "Add Hello World app to Cloud Source
Repositories"
2 files changed, 22 insertions(+)
create mode 100644 app.yaml
create mode 100644 main.py
Using the git push command, add the contents of the local Git repository to Cloud Source Repositories:
$ git push origin master
Git pushes the files from the master branch to the origin remote. Output similar to the following is displayed:
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 555 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://source.developers.google.com/p/uconn-engr/r/hello-world
* [new branch] master -> master
View files in the repository
In the Google Cloud Console, open Cloud Source Repositories.
Open Cloud Source Repositories
Go to Source Repositories
Click into the hello world repository
And the files are located in the repository and accessible
Creating an empty repository
You can use Cloud Source Repositories to create a new, empty repository. Creating a repository is useful when you want to start a project or back up a Git repository using Cloud Source Repositories
Click Add repository.(upper left part of the screen
Click on Create new repository and hit continue
Type in a name for the repository and assign it to a project
Set up so code can interact with Google Cloud SDK
After switching to new locat Git repository
Place all your files into the structure needed for the project
Once all the files are in place at the $ prompt you need to add the files to the repository
git config credential.helper gcloud.sh ?
$ git remote add google https://source.developers.google.com/p/uconn-datastore/r/create-nosql-records
$ git push --all google
https://git-scm.com/docs/git-push
Use git push to push commits made on your local branch to a remote repository
$ git add --all
The git add is a command, which adds changes in the working directory to the staging area. With the help of this command, you tell Git that you want to add updates to a certain file in the next commit.
$ git commit -m "initial commit"
In Git, commit is the term used for saving changes. Git does not add changes to a commit automatically. You need to indicate which file and changes need to be saved before running the Git commit command. The commit command does not save changes in remote servers, only in the local repository of Git
$ git push -u origin master
git push origin master will push your changes to the remote server. "master" refers to master branch in your repository.
They now appear in the Cloud Source Repositories
$
git config --global credential.'https://source.developers.google.com'.helper gcloud.sh
https://help.github.com/en/github
No comments:
Post a Comment