Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial review to help clarity #20

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Git_GitHub/1_Git_and_GitHub.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
# Git and GitHub

Git is the most widely used version control software (VCS). It is a very powerful tool to know, and we are here to learn how to get started with it.
Git and GitHub are two different tools to facilitate version control, collaboration and sharing. It's important to understand that Git is not GitHub
Git and GitHub are two different tools to facilitate version control, collaboration and sharing. It's important to understand that Git is not GitHub.

Git is a software that operates locally at your machine.
A Git repository in Git, is a project in a "Folder". It contains all of the files and folders associated with your project and all the various versions of them over time. That helps to manage file changes. If you are just using Git for version control of the repository and you don't want to share your projects, you might never use GitHub.
A repository in Git is a project in a "Folder". This folder contains all of the files and folders associated with your project and all the various versions of them over time. That helps to manage file changes. If you are just using Git for version control of the repository and you don't want to share your projects, you might never use GitHub.

GitHub is a service that hosts Git repositories in the cloud. Users could share a repository, and collaborate at various steps of the project.

**[DW]** all the three images below are not showing [/DW]
**[MT]** I know it only shows up in the local machine. do you know how to fix it? [/MT]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no figures in a fig subdirectory of this repository. The directory and the png need to be added.


![Git_GitHub](./fig/image_1.png)



A repository contains all of the files and folders associated with your project. It also includes the revision history of each file. The file history is a series of snapshots in time, known as commits. A commit tells Git that you made some changes that you want to record.

When you make a commit in Git you will see “commit to main.” This refers to the default branch, which can be thought of as the production-ready version of your project.
If you want to share your repository you connect to a GitHub account. You need to create a GitHub account for that purpose. In the GitHub the repository could be accessible by multiple users.
When you make a commit in Git you will see “commit to main.” This refers to the default branch 'main', which can be thought of as the production-ready version of your project.
If you want to share your repository, you connect to a GitHub account. You need to create a GitHub account for that purpose. In GitHub the repository could be accessible by multiple users.

![Git_upload](./fig/git_checkout.png)

Your collaborators can download the GitHub repository to their local computer and work on a part of a project making a branch. Then they upload their work and request a review before is merged into the main branch.
Your collaborators can download the GitHub repository to their local computer and work on a part of a project making a branch. Then they upload their work and request a review before it is merged into the main branch.

![Git_upload](./fig/image_3.png)

Expand Down
63 changes: 37 additions & 26 deletions Git_GitHub/3_First_Git_Commands.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
# First Git Commands
You should have already completed the setup instructions for this workshop and have Git installed. Launch a command line environment (in Windows launch “Git Bash” from the Start Menu, on Linux or Mac start a new Terminal). We will use this command line interface throughout these materials, we prefer this for educational reasons because the command line is a common environment for all the operating systems.
**[DW]** The episode before this is "Git and Github" which is about concept. Here, this episode moves to hands-on use of Git. If we provide a link to the setup instruction, it will help with the transition from concept to practical. [/DW]
**[MT]** I would move it to the 1_Git-and_GitHub and name it 1_Git-and_GitHub_firts_commands. [/MT]

You must provide some extra information before it is ready to interact with Git.
The information is related to the person who uses Git and it gives the identity of the user in any project which you might work on your computer. In collaborative projects this is used to distinguish who has made what changes. You only need to perform the above commands once for each new computer Git is installed on.
You should have already completed the setup instructions for this workshop and have it installed. You might have launched a command line environment (in Windows launch “Git Bash” from the Start Menu, on Linux or Mac start a new Terminal). We will use this command line interface throughout these materials, we prefer this for educational reasons because the command line is a common environment for all the operating systems.

You must provide some extra information before it is ready to interact with git.
The information is related to the person who uses git and it gives the identity of the user in any project which you might work on your computer. In collaborative projects this is used to distinguish who has made what changes. You only need to perform the above commands once for each new computer Git is installed on.

**[DW]** A little more hand holding might be useful, i.e. show a picture of Bash, and then explain the git config commands. [/DW]
**[MT]** OK I'll creare screen shots for eveything. I have created a presentation and it has short videos in it. That's why I havent got the images here.

```bash
git config --global user.name "FIRST_NAME LAST_NAME" # Use the name that you wish to be identified
Expand All @@ -11,12 +17,11 @@ The information is related to the person who uses Git and it gives the identity
```

## Creating a Repository
Now the Git is ready and we will use it in a new project.
Now Git is ready and we will use it in a new project.
In Git terminology a project is called a repository (frequently shortened to repo).
Let's start a project withing your directories. Lets create a directory called cooking where we will store some folders and recipes.
\Users\mary\cooking
Let's start a project within your directories. Let's create a directory called 'cooking' where we will store some folders and recipes. We want 'cooking' to be immediately under our home directory, e.g. \Users\mary\cooking

Within cooking we create (with mkdir) other directories, recipes, tools, videos. We go to the directory recipes and we create pizza.md and cake.md files. There we write and instructions
Within 'cooking' we create (with `mkdir`) other directories: 'recipes', 'tools', 'videos'. We go to the directory recipes and we create files 'pizza.md' and 'cake.md' files.
```bash
pwd
```
Expand Down Expand Up @@ -49,6 +54,9 @@ Create pizza.md and cake.md
touch pizza.md cake.md
ls
```

**[DW]** An output needing for the 'ls' command just above here. [/DW]

## Create a Git repository
To start using Git with our recipes we need to create a repository for it. Make sure the current working directory for your terminal is recipes and run: **git init**

Expand All @@ -71,29 +79,31 @@ Output
. .. .git cake.md pizza.md
```
We can see the hidden directory .git in the recipes directory, this signifies that it is a Git directory.
In general we can create various Git repositories within your projects, whatever happens in those folders, whatever git commands you run , whatever history is stored there are completely separated and not connected.
In general we can create various Git repositories within your projects. Whatever happens in those folders, whatever git commands you run, whatever history is stored, they are completely separated and not connected.
**BEWARE** when you initialise a Git repository inside a folder all the nested folders within it are automatically in the Git repository (there is no need to initialise Git within the directory again).

It is a common mistake to create Git directories in some or all the subdirectories, this complicates the process and end in error messages.

The folder tree of this project should look like the picture. Only the directory recipes is a Git repo. (the Git sign is added for visualizing that we have initiated a Git repo, you will not see it at your computer)

**[DW]** Picture belog does not show up [/DW]

![Directories_tree](./fig/repo_directories_tree.png)

## Master and main branches (You DON'T need to TYPE the COMMANDS in this section if you've done them in the set-up)
Traditionally, the default branch name in Git whenever you init a repository was master. However, the sensitivity of the online community has shifted lately and GitHub, use now main as the default name instead.
Traditionally, the default branch name in Git whenever you init a repository was master. However, the sensitivity of the online community has shifted lately and GitHub now use 'main' as the default name instead.
You can read the reason in this [link](https://www.theserverside.com/feature/).

**If you have done this step in the set up page and you don't need to repeat it here**

If you are using git version 2.28 or higher (you can find the version you are using with git --version) you can change the default branch name for all new repositories with:
If you are using Git version 2.28 or higher (you can find the version you are using with git --version) you can change the default branch name to 'main' for all new repositories with:

```bash
git config --global init.defaultBranch main
```
With this command the word "master" in the Git code, it is being replaced by the word "master" as the GitHub uses it. So there is an alignment for the main branch between Git and GitHub
With this command the word "master" in the Git code is replaced by the word "main" and GitHub will use it from then on. So there is an alignment for the main branch between Git and GitHub.

For existing repositories or if your git version is lower than 2.28, you can create the master branch normally and then re-name it with:
For existing repositories or if your Git version is lower than 2.28, you can create the master branch normally and then re-name it with:

```bash
git branch -m master main
Expand Down Expand Up @@ -128,11 +138,11 @@ This is a very useful command that we will use a lot. It should be your first po
Don’t worry about all the output for now, the important bit is that the 2 directories and their files we already have are untracked in the repository (directory).

We want to add the files to the list of files tracked by Git. Git does not track any files automatically and you need make a conscious decision to add a file.
At the next session 4_Git_Commit_Commands you will be instructed how to make changes over time and save them in tracked versions indicated by messages.
At the next session **[DW]** check session name [/DW/] 4_Git_Commit_Commands you will be instructed how to make changes over time and save them in tracked versions indicated by messages.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a link please?


## Common mistake of creating multiple Git repos

As discussed above, creating Git repositories within and Git repository will cause confusion!!
As discussed above, creating Git repositories within an existing Git repository will cause confusion!!

![Warning](./fig/Warning_repo.png)

Expand All @@ -158,10 +168,10 @@ Initialized empty Git repository in /Users/mary/cooking/recipes/food/.git/
(base) mary food % ls -a
. .. .git curry.md pizza.md
```
Always check with **ls -a** and you observe that amongst the files in the food directory there is a .git hidden directory that you don't want to be there as it will confuse Git.
You need to remove it using the ** rm -r** command for removing directories.
Always check with **ls -a** and you observe that amongst the files in the food directory there is a .git hidden directory that you don't want it to be there as it will confuse Git.
You need to remove it using the **rm -r** command for removing directories.

make sure you are in the food directory
Make sure you are in the food directory
```base
food % rm -r .git
(base) mary food % ls -a
Expand All @@ -172,7 +182,7 @@ Output
```
Now there is only the parent directory (recipes) that is a Git directory and we can use Git as main branch.

Another way (which is recommended ) is to go one directory ahead (ie recipes) and we remove the .git repository at foods. ALWAYS CHECK with **pwd**
Another way (which is recommended) is to go one directory ahead (ie recipes) and we remove the .git repository at foods. ALWAYS CHECK with **pwd**

``` bash
cd ..
Expand All @@ -193,8 +203,8 @@ Output
```bash
. .. curry.md pizza.md
```
This is recommended when there are many nested git directories in the parent (ie recipes)
But be careful the syntax! Running this command in the wrong directory will remove the entire Git history of a project you might want to keep. Therefore, always check your current directory using the command pwd
This is recommended when there are many nested git directories in the parent (ie recipes).
But be careful the syntax! Running this command in the wrong directory will remove the entire Git history of a project you might want to keep. Therefore, always check your current directory using the command `pwd`.

In this section we present:

Expand All @@ -205,10 +215,11 @@ In this section we present:

Key Points

Use **git config -- global** can configure a user name, email address, editor, and other preferences once per machine.
**[DW]** The first three are not covered in this episode[/DW]

**git config -h** Opens the use of the config, Opens the Git manual
**git config --help**
**git init** initializes a repository.
Git stores all of its repository data in the **.git** directory.
**rm -r .git** # Removes the git directory (rm -r <directory name>)
* Use **git config -- global** to configure a user name, email address, editor, and other preferences once per machine.
* **git config -h** Opens the use of the config, Opens the Git manual
* **git config --help**
* **git init** initializes a repository.
* Git stores all of its repository data in the **.git** directory.
* **rm -r .git** # Removes the git directory (rm -r <directory name>)