|
git
is open source industry standard distributed
revision control system (RCS). There have been other RCS such as
SVN and CVS. git
was developed by Linus Torvalds the
author and maintainer of the Linux Kernel. There are thousands of
Linux developers using git
.
A RCS is software which allows multiple users to save their work in an ordered fashion. The RCS takes care of merging files when multiple people are working on the same file. Additionally it acts as a chronological snapshot of the work, allowing the developer to easily roll back to previous versions.
git
?Although initially developed to be used with the Linux Kernel, git
has become the standard RCS for application development as well.
Because it was designed from the ground up to be a distributed
system, copies of the git repository can be located at different
locations, by different people, and git
handles the
merging of the differences. This means that using free services
such as github or gitlab become an automatic back up
of your project, complete with all of the versioning history.
git
Installing git is quite easy, on Pi Linux, just type:
sudo apt-get install git
git
repositoryIt is easy to create a git
repository, just:
git
repositorygit
repositoryCreating a git
repository is as easy as changing to
your project subdirectory, and typing:
git init
It is also a good idea to add your name and email address to the repository:
git config --global user.name "Craig Miller" Or Deid...
git config --global user.email cvmiller@gmail.com
Of course the whole point is adding your project files. Copy or move your project files into the project subdirectory.
If you are going to share your project with the world, then it is a good idea to have a README.md file explaining what your project is, and how to use it. And a license file. I recommend an open source license such as GPL (Gnu Public License) or BSD (Berkeley Standard Distribution). You can find these online.
git
repositoryOnce your project files, README.md, license files are in the subdirectory, it is time to add them to the repository. Type the following:
git add .The period means add everything in this directory
The files have been added, so the repository knows about them, but any changes you may have made have not been committed to the repository. Think of it as a local copy which no one else can see. When ready, commit the files to the repository:
git commit -a
An editor will pop up, asking you to type a description of this commit
.
Type something that makes sense to you (and others). Since this is
the initial commit, something like the following is common:
Initial commit
You are all done, take a break, and get a coffee!
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: pistuff.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
git add
pistuff.txt
git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: pistuff.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
modified: pistuff.txt
[master 065781a] Added .gitignore and modified pistuff for git status demogit status
2 files changed, 2 insertions(+)
create mode 100644 .gitignore
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
And, everything is up to date.
git log
pi@rasport4:~/gitDemo/pi $ git log
commit 065781ab3e21939fb462ec29f8c6ba8ccc5ca30d
Author: deid <deid@drsol.com>
Date: Sun May 12 09:07:25 2019 -0700
Added .gitignore and modified pistuff for git status demo
commit 129a1fb2edb53d5d9d7dae02822cc717cf01635f
Author: deid <deid@drsol.com>
Date: Sat May 11 11:35:13 2019 -0700
added .gitignore to be added to notes
commit e9fa696861e8091d6b7feb2771e5eb96473e5ab3
Author: deid <deid@drsol.com>
Date: Sat May 11 11:18:43 2019 -0700
todo
commit 5aba24e072db47437e147d05210b8aee0e3dc5a2
Author: deid <deid@drsol.com>
Date: Sat May 11 10:48:27 2019 -0700
Added fore fathers.
git diff
diff --git a/pistuff.txt b/pistuff.txt
index 6f3253f..27e7784 100644
--- a/pistuff.txt
+++ b/pistuff.txt
@@ -8,3 +8,6 @@ git diff
.gitignore will ignore its contents
Added this so git status will show something.
+
+a line for diff
+
git
version info and
status.git
doesn't have to be all
command line, although most folks probably use the CLI.
A useful tool to see the history, and what has changed in a
repository is gitk
. It shows those comments you made
when you made your commits as well as a chronological history of
your commits, high lighting the differences with each commit.
You will have to install gitk:
sudo apt-get install gitk
then:
gitk <repo
name>
As you can see it is a good idea to add the version number of
your project in the commit comment.
git
repo on githubSo far your repository is only located on your computer. If your computer crashes with an unrecoverable hard drive (or SSD), then all of your hard work is lost. Fortunately, there are services such as github or gitlab which will not only store your repository, but share it with the world, if you would like.
To create a copy of your repository on github you just need to do the following steps:
push
the repo
to githubSteps 1, and 2 only have to be done once. Step 3 only has to be done once per repository (each project should be its own repository)
Go to github.com and create an account.
Click the + -> New Repository on the
github's web interface, or the New in the upper left. And
follow the directions. Once the Repository is created, it will
give you a few lines to paste into your terminal to setup your
local git
to push up to github. Github has documentation
on setting up a remote.
The lines will look something like:
- git remote add origin https://github.com/deid/thing.git
- git push -u origin master
Create an ssh key. I created one for gethub - different
from my other ones.
This creates a bit of complexity.
ssh-keygen -t rsa
When prompted for a file name to save the keys
e.g. "Enter file
in which to save the key (/home/deid/.ssh/id_rsa):" Don't
take the default. Name it something else and save it in
whatever directory makes sense to you.Now that you have ssh rsa keys, cat the public key
cat <whatever you named it>
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPXgkmnGoPL7/KSP3+QqLPH8vfEbKlmBCgS+8UQ6ZTX51WPaNSfu13M6U8Mi6UGyfHoZApUCfS60QRIr1wedD37E+lmqPJVpvnAHA4JACOavhcUuCMlbBiEh1dDo9/ji58AkdGhRYUwDM8CpN6qAsawVzBt2of7IOEPfJ4o8RgxOWtTnmkRAOZCCjw+/5ZaZ4/OFJafQZTc9WRgSiRbt6KYrZ2rGfQUYqxuJkG+mok2/QwxxpmzbwiWie2plI+0zrYFSDEbcVsLxi13971aVPSnnsTBEk50+nuEcwc2j7puIByuSJ2PDbxCAZHUc/8Ghrl8tD3Iu2wvsioeRC+VBDB cvmiller@asus_c201pa
Host github.com
HostName github.com
IdentityFile /home/pi/gitDemo/gitdemo
user git
- git remote add origin git@github.com:<Username>/<Project>.git
- git push -u origin master
Then to push further changes to your project up to github, just type:
<make changes> <test changes?>
git add . # to add the changes
git commit -a # to commit the changes
git push # to send the changes to github
Point your browser to your project on github and see your files
you just pushed
15 Feb 2019 Modified 12 May 2019 Deid Reimer