-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from MonashDeepNeuron/dev
Git Gut - v1.0.0
- Loading branch information
Showing
35 changed files
with
875 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
book | ||
*.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,34 @@ | ||
# Summary | ||
|
||
- [Welcome](./home.md) | ||
- [TL;DR](./tlrd.md) | ||
- [Git](./git/about.md) | ||
<!-- - []() --> | ||
- [GitHub](./github/about.md) | ||
<!-- - []() --> | ||
- [Acknowledgements](./acknowledgements.md) | ||
- [Welcome](home.md) | ||
- [TL;DR](tlrd.md) | ||
|
||
- [Git](git/git.md) | ||
- [Installing Git](git/install.md) | ||
- [Common Commands](git/commands.md) | ||
- [Creating a repository](git/create.md) | ||
- [Changes, Staging and Commits](git/changes-staging-commits.md) | ||
- [Branches, Stashes and Tags](git/branches.md) | ||
- [Merging](git/merging.md) | ||
- [Rebasing](git/rebasing.md) | ||
- [Configuring Git](git/config.md) | ||
|
||
- [GitHub](github/github.md) | ||
- [Setup](github/setup.md) | ||
- [Creating, Cloning and Uploading Remote Repositories](github/create-cloning-upload.md) | ||
- [Push, Pull, Fetch](github/push-pull-fetch.md) | ||
- [Forks](github/forks.md) | ||
- [Template Repositories](github/templates.md) | ||
- [Collaborating](github/collaboration.md) | ||
- [Issues](github/issues.md) | ||
- [Pull Requests](github/pr.md) | ||
- [Milestones](github/milestones.md) | ||
- [Tags and Releases](github/releases.md) | ||
- [Wikis]() <!-- (github/wikis.md) --> | ||
- [Discussions](github/discussions.md) | ||
- [Licensing and OSS](github/licenses-oss.md) | ||
- [A Sample Workflow](github/workflow.md) | ||
- [GitHub Pages](github/pages.md) | ||
- [GitHub Organisations]() <!-- (github/orgs.md) --> | ||
|
||
- [Acknowledgements](acknowledgements.md) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Branches, Stashes and Tags | ||
|
||
Git has various ways of storing and marking the different states and histories of a repo. The most common is a _branch_, which serves as a logically separate history for a repository. This allows various changes from multiple people to not conflict with each other. _Stashes_ are temporary stores of changes that can be pushed to or popped from, kind of like a stack of changes. _Tags_ are named markers for commits in a repo's history. | ||
|
||
## Branches | ||
|
||
To create a new branch, you simply use the `git branch` with the name of the branch as the argument. This will create a new branch `HEAD` at the commit you are currently at. You can also pass a commit hash as a second argument to create the branch at that associated commit. Renaming a branch can be achieved by using the `-m` or `-M` (forced) flags and passing the old name (optional) and new name as arguments respectively. You can also delete branches using the `-d` flag. To switch to a branch we use the `checkout` command, supplying the branch name as an argument. | ||
|
||
```sh | ||
# Create a new branch | ||
git branch new-branch | ||
|
||
# Switch to the new branch | ||
git checkout new-branch | ||
|
||
# Rename the current branch | ||
git branch -M new-branch-2 | ||
|
||
# Switch back to the main branch | ||
git checkout main | ||
|
||
# Delete the previously created branch | ||
git branch -d new-branch-2 | ||
``` | ||
|
||
> Note: You can create a new branch and switch to it using the `-b` flag with the `checkout` command. | ||
> | ||
> ```sh | ||
> git checkout -b new-branch | ||
> ``` | ||
## Stashes | ||
Stashes store WIP changes that can be reapplied on to the currently checked out commit. Stashes are labelled by a number value starting at 0, indicating the most recent stash. You can `pop` or `drop` (delete) a stash from a particular index by providing it as an argument, with the default being the most recent stash. You can also list a repo's stashes using the `list` sub-command. | ||
```sh | ||
# Create a stash | ||
git stash | ||
# Pop the most recent stash | ||
git stash pop | ||
# Drop (delete) the most recent stash | ||
git stash drop | ||
# Stash with a message | ||
git stash -m "Stash 1" | ||
# Some changes | ||
git stash -m "Stash 2" | ||
# Some changes | ||
git stash -m "Stash 3" | ||
# List stashes | ||
git stash list | ||
stash@{0}: On main: Stash 3 | ||
stash@{1}: On main: Stash 2 | ||
stash@{2}: On main: Stash 1 | ||
stash@{3}: WIP on main: cea4a92 current HEAD commit message | ||
git stash pop 1 | ||
git stash list | ||
stash@{0}: On main: Stash 3 | ||
stash@{1}: On main: Stash 1 | ||
stash@{2}: WIP on main: cea4a92 current HEAD commit message | ||
git stash drop 1 | ||
git stash list | ||
stash@{0}: On main: Stash 3 | ||
stash@{1}: WIP on main: cea4a92 current HEAD commit message | ||
``` | ||
## Tags | ||
Tags allow us to name a particular commit such that it can be referenced and changed to it. Tagging is mostly used to mark certain versions of a codebase. Tags can be created using the `tag` command and providing a label for the tag. Like most of Git, the `-d` flag can be used to delete a tag as well. | ||
```sh | ||
# Create tag | ||
git tag v1.0.0 | ||
# List tags | ||
git tag | ||
v1.0.0 | ||
# Delete tag | ||
git tag -d v1.0.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Changes, Staging and Commits | ||
|
||
Whenever you make changes to the contents of a repository, these changes will be compared as a diff between the working tree and the `HEAD` of the repository's history. To view which files have changed you can run the `git status` command. Once you are happy with your changes, you can `git add <file>` them to the file index for staging. You can specify certain files you want to keep or use `.` to stage all new changes. | ||
|
||
Finally you can then commit your changes. Commits are saved snapshots of a repo's state. When you create a commit, a hash value is generated for it, this is used to jump back to the commit using `switch` or `checkout`. Commits also have a short message associated with it to describe the changes made in the commit. | ||
|
||
```sh | ||
# Stage all changes in repo | ||
git add . | ||
|
||
# Commit changes | ||
git commit -m "Commit message" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Common Git Commands | ||
|
||
Git is predominately used through its command line interface (CLI). This means Git operates using a variety of different commands (and even sub-commands, command options for commands). Some of the most commonly used commands and their purpose: | ||
|
||
| Command | Description | | ||
| :--------: | :-----------------------------------------------------------------------------------: | | ||
| `init` | Initialise a repository | | ||
| `clone` | Clone repository from remote host at URL | | ||
| `checkout` | Checkout to branch or commit | | ||
| `branch` | Create branch | | ||
| `add` | Add files to commit stage | | ||
| `commit` | Commit staged changes | | ||
| `merge` | Merge changes from another branch into current branch | | ||
| `push` | Push changes to remote repository | | ||
| `pull` | Pull changes from remote repository | | ||
| `fetch` | Pull changes from remote repository without integrating changes into local repository | | ||
| `rebase` | Reapply commits on top of new branch `HEAD` | | ||
| `status` | List the currently modified files and status of remotes | | ||
| `tag` | Create or list a tag at the current `HEAD` | | ||
|
||
There are many more commands within Git's CLI. You can view them and their functionality using Git's Manpage. To access the Manpage run the following commands. | ||
|
||
```sh | ||
man git | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Configuring Git | ||
|
||
The properties and behaviour of Git can be customized using special files within your repo. These can control which files Git tracks as well as give certain properties to certain files within a Git repo. | ||
|
||
## `.gitignore` | ||
|
||
The `.gitignore` file is used to specify files or file patterns you wish for Git to ignore. File patterns are specified using Unix-based [globbing](https://linux.die.net/man/7/glob) (ie. the use of wildcard patterns). | ||
|
||
## `.gitattributes` | ||
|
||
The `.gitattributes` file is used to specify the attributes of files or file patterns. One particular useful case of the `.gitattributes` file is to ensure the correct End-of-Line (EOL) characters are used in certain files as the default choice between Unix-like systems and Windows is different which can lead to some unique bugs and inconsistencies when collaborating with people using different systems. It also allows you to control exactly which files these attributes apply to ensuring only the right files are affected. | ||
|
||
| Pattern | Examples | Explanation | | ||
| :----------------------------------: | :---------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | | ||
| `**/logs` | `logs/debug.log` `logs/monday/foo.bar` `build/logs/debug.log` | You can prepend a pattern with a double asterisk to match directories anywhere in the repository. | | ||
| `**/logs/debug.log` | `logs/debug.log` `build/logs/debug.log` but not `logs/build/debug.log` | You can also use a double asterisk to match files based on their name and the name of their parent directory. | | ||
| `*.log` | `debug.log` `foo.log` `.log` `logs/debug.log` | An asterisk is a wildcard that matches zero or more characters. | | ||
| `*.log` `!important.log` | `debug.log` `trace.log` but not `important.log` `logs/important.log` | Prepending an exclamation mark to a pattern negates it. If a file matches a pattern, but also matches a negating pattern defined later in the file, it will not be ignored. | | ||
| `*.log` `!important/*.log` `trace.*` | `debug.log` `important/trace.log` but not `important/debug.log` | Patterns defined after a negating pattern will re-ignore any previously negated files. | | ||
| `/debug.log` | `debug.log` but not `logs/debug.log` | Prepending a slash matches files only in the repository root. | | ||
| `debug.log` | `debug.log` `logs/debug.log` | By default, patterns match files in any directory | | ||
| `debug?.log` | `debug0.log` `debugg.log` but not `debug10.log` | A question mark matches exactly one character. | | ||
| `debug[0-9].log` | `debug0.log` `debug1.log` but not `debug10.log` | Square brackets can also be used to match a single character from a specified range. | | ||
| `debug[01].log` | `debug0.log` `debug1.log` but not `debug2.log` `debug01.log` | Square brackets match a single character form the specified set. | | ||
| `debug[!01].log` | `debug2.log` but not `debug0.log` `debug1.log` `debug01.log` | An exclamation mark can be used to match any character except one from the specified set. | | ||
| `debug[a-z].log` | `debuga.log` `debugb.log` but not `debug1.log` | Ranges can be numeric or alphabetic. | | ||
| `logs` | `logs` `logs/debug.log` `logs/latest/foo.bar` `build/logs` `build/logs/debug.log` | If you don't append a slash, the pattern will match both files and the contents of directories with that name. In the example matches on the left, both directories and files named logs are ignored | | ||
| `logs/` | `logs/debug.log` `logs/latest/foo.bar` `build/logs/foo.bar` `build/logs/latest/debug.log` | Appending a slash indicates the pattern is a directory. The entire contents of any directory in the repository matching that name – including all of its files and subdirectories – will be ignored | | ||
| `logs/` `!logs/important.log` | `logs/debug.log` `logs/important.log` | Wait a minute! Shouldn't `logs/important.log` be negated in the example on the left Nope! Due to a performance-related quirk in Git, you can not negate a file that is ignored due to a pattern matching a directory | | ||
| `logs/**/debug.log` | `logs/debug.log` `logs/monday/debug.log` `logs/monday/pm/debug.log` | A double asterisk matches zero or more directories. | | ||
| `logs/*day/debug.log` | `logs/monday/debug.log` `logs/tuesday/debug.log` but not `logs/latest/debug.log` | Wildcards can be used in directory names as well. | | ||
| logs/debug.log | `logs/debug.log` but not `debug.log` `build/logs/debug.log` | Patterns specifying a file in a particular directory are relative to the repository root. (You can prepend a slash if you like, but it doesn't do anything special.) | | ||
|
||
> Note: | ||
> | ||
> - These explanations assume your `.gitignore` file is in the top level directory of your repository, as is the convention. If your repository has multiple `.gitignore` files, simply mentally replace "repository root" with "directory containing the `.gitignore` file" (and consider unifying them, for the sanity of your team). | ||
> - Additionally, lines starting `#` are treated as comments and a `\` character can be prepended to a character that usually has a special meaning to escape it (ie. match the literal character `[` (using `\[` in the `.gitignore`) that is in a file name instead of start a match group). | ||
### Example `.gitattributes` | ||
|
||
```.gitattributes | ||
# Use the 'line feed' EOL character for all files | ||
* eol=lf | ||
# Use the 'carriage return & line feed' EOL character for text files | ||
*.txt eol=crlf | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Creating a Repository | ||
|
||
To create a repository you first want to create a new directory. Then you can initialise this directory as the root of your new repo. | ||
|
||
```sh | ||
# Make a new directory/folder to be the root of your new repo | ||
mkdir project | ||
|
||
# Navigate into the root directory | ||
cd project | ||
|
||
# Initialise your new repo | ||
git init | ||
``` |
Oops, something went wrong.