... | ... | @@ -2201,17 +2201,27 @@ would use vimdiff with... |
|
|
git difftool HEAD^
|
|
|
```
|
|
|
|
|
|
The command (at the time of writing) would generate...
|
|
|
|
|
|
![git difftool example](git-vimdiff-example.PNG)
|
|
|
|
|
|
|
|
|
The `git blame` command can provide per line change information. However, I
|
|
|
will leave discussion of `git blame` to a live demo later in this discussion.
|
|
|
|
|
|
---
|
|
|
|
|
|
# Setting Up a Local Git Repository
|
|
|
|
|
|
I decided to reverse the traditional order of a *working with git* discussion.
|
|
|
Most discussions would start with the basic commands. A discussion of `git log`,
|
|
|
`git diff`, and branches would normally be left as follow-up discussion.
|
|
|
|
|
|
There are two main goals for this discussion:
|
|
|
|
|
|
1. Motivate the use of Git (i.e., show git's value).
|
|
|
2. Demonstrate how to set up a basic git repo.
|
|
|
|
|
|
# Basic Commands
|
|
|
## Basic Commands
|
|
|
|
|
|
Before we can discuss *merge* and *rebase*, we must focus on the basic
|
|
|
commands:
|
... | ... | @@ -2223,11 +2233,100 @@ commands: |
|
|
- `git commit` and `git commit -m` - package together all *staged* changes
|
|
|
- `git push` - *push* (i.e., send) all local changes to a remote repo.
|
|
|
- `git pull` - *pull* (i.e., retrieve) all changes from a remote repo.
|
|
|
|
|
|
We have already discussed a few of the more advanced commands...
|
|
|
|
|
|
- `git log` - examine the commit history. *This covered in a future section*.
|
|
|
- `git diff` - examine the differences between two commits.
|
|
|
- `git difftool` - examine the differences between two commits in a more human
|
|
|
readable form.
|
|
|
|
|
|
There is one more type of command we will need to set up a repository... the
|
|
|
`git config` command. We will use `git config` to set:
|
|
|
|
|
|
- author name
|
|
|
- author email
|
|
|
|
|
|
|
|
|
## Getting Started
|
|
|
|
|
|
The practical (i.e., hands-on) part of this workshop will assume a terminal
|
|
|
environment and terminal commands. You may use a graphical client, e.g.,
|
|
|
|
|
|
- [Eclipse](https://www.eclipse.org/downloads/packages/release/2019-12/r/eclipse-ide-enterprise-java-developers)
|
|
|
- [VSCode](https://code.visualstudio.com/)
|
|
|
- [Git Kraken](https://www.gitkraken.com/)
|
|
|
- [gitk](https://git-scm.com/docs/gitk)
|
|
|
- [Sublime Text or Sublime Merge](https://www.sublimetext.com/)
|
|
|
|
|
|
However, if you opt to use a graphical client you will need to locate the
|
|
|
equivalent git commands within the client.
|
|
|
|
|
|
|
|
|
### Opening the Terminal
|
|
|
|
|
|
If you are on Windows open:
|
|
|
|
|
|
- [Cygwin](https://www.cygwin.com/)
|
|
|
- [WSL Bash](https://docs.microsoft.com/en-us/windows/wsl/install-win10)
|
|
|
- [Git Bash](https://www.atlassian.com/git/tutorials/git-bash)
|
|
|
- [git for Windows](https://gitforwindows.org/)
|
|
|
|
|
|
If you are on macOS or Linux open your terminal.
|
|
|
|
|
|
> If you need to install git, <https://git-scm.com/downloads> provides a set of
|
|
|
> instructions for Windows, macOS and Linux.
|
|
|
|
|
|
|
|
|
### Creating a New Repository
|
|
|
|
|
|
We will focus on creating a brand new local repository (repo). For now we will
|
|
|
not link it to GitHub, GitLab, or another remote host.
|
|
|
|
|
|
Since git repos need code... we will use one of my Python lectures from CS 417
|
|
|
(Computation Methods). Open [Python non-linear solver discussion](https://www.cs.odu.edu/~tkennedy/cs417/s20/Public/solverDiscussion/)
|
|
|
in your web browser.
|
|
|
|
|
|
1. In your terminal create a new folder. You may use any name you choose (provided
|
|
|
there are not spaces in the directory name.
|
|
|
|
|
|
```sh
|
|
|
mkdir git-workshop
|
|
|
```
|
|
|
|
|
|
2. Change into the new folder.
|
|
|
|
|
|
```sh
|
|
|
cd git-workshop
|
|
|
```
|
|
|
|
|
|
3. Initialize the git repo.
|
|
|
|
|
|
```sh
|
|
|
git init .
|
|
|
```
|
|
|
|
|
|
4. Set your name (I have entered mine as an example).
|
|
|
|
|
|
```sh
|
|
|
git config user.name "Thomas J. Kennedy"
|
|
|
|
|
|
5. Set your email (I have entered mine as an example).
|
|
|
|
|
|
```sh
|
|
|
git config user.name "tkennedy@cs.odu.edu"
|
|
|
```
|
|
|
|
|
|
6. *Note:* I prefer to set my name and email for each repo. If you want to set
|
|
|
your name and email globally (i.e., for all repos) add `--global` after
|
|
|
`git config`.
|
|
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
Let us focus on how each command is used *[in situ](https://www.merriam-webster.com/dictionary/in%20situ)*.
|
|
|
|
|
|
\bSidebar
|
... | ... | |