From 7a28cd79b3ae4a014c1debf740a942da5506ef34 Mon Sep 17 00:00:00 2001 From: waldek Date: Wed, 7 Apr 2021 22:13:21 +0200 Subject: [PATCH] completes git documentation but is only a first pass --- Git/readme.md | 101 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 26 deletions(-) diff --git a/Git/readme.md b/Git/readme.md index ca162b5..029c0ec 100644 --- a/Git/readme.md +++ b/Git/readme.md @@ -1,57 +1,106 @@ # Git + ## Description + Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency. -## Usefull links -- [Git Cheat Sheet](https://education.github.com/git-cheat-sheet-education.pdf) +## Useful links + +- a very handy [cheat sheet](https://gitea.86thumbs.net/waldek/LinuxSysAdminsDoc/raw/branch/master/Git/SWTM-2088_Atlassian-Git-Cheatsheet.pdf) in pdf outlines the basic Git commands to help you learn git, as well as more advanced concepts such as Git branches, remote repositories, undoing changes, and much much more +- the main git [documentation](https://git-scm.com/book/en/v2) is an excellent reference manual ## Git System + +The diagram below outlines the main gt commands and how they relate to the version control system. +In our classes the **local** is the repository on your own computer and the **remote** is the corresponding repository you create on our [gitea](https://gitea.86thumbs.net/) server. +Nothing is stopping you from hosting your own gitea server or pushing your local repository to a third party server such as [gitlab](https://about.gitlab.com/). + ![Git System](img/Git_Guide.png) -= + +A remote repository is often referenced by the name **origin** but this naming is fully up to you. +If you would push to multiple remote locations you could for example add one named gitea for our own and gitlab for your gitlab account. + +```bash +git remote add gitea https://gitea.86thumbs.net/USER/REPOSITORY.git +git remote add gitlab https://gitlab.com/USER/REPOSITORY.git +``` # Basic commands ## Git clone -Clone repo located at **\** onto local machine. Original repo can be located on the local filesystem or on a remote machine via **HTTPS** or **SSH**. -> git clone +Clone repo located at **\** onto local machine. Original repo can be located on the local file system or on a remote machine via **HTTPS** or **SSH**. +Throughout the classes you'll first clone via HTTPS but once we'll learn about [RSA](https://en.wikipedia.org/wiki/RSA_(cryptosystem)) you'll be able to clone, push and pull over SSH. -## Git init -Initialize an existing directory as a Git repository -> git init +```bash +git clone $REPOSITORY_URL -Create empty Git repo in specified directory. Run with no arguments to initialize the current directory as a git repository. - -> $ git init \ -= - -## Git status -List which files are staged, unstaged, and untracked. - -> $ git status +``` ## Git config --global name & email -Must be identifiable for credit when review version history. -> $ git config --global user.name “[firstname lastname]” +Before you can use git you **need** to identity yourself. +Git uses this information in each commit so we can keep track of **who** did **what** **when**. -> $ git config --global user.email “[valid-email]” +```bash +git config --global user.name "$FISTNAME $LASTNAME" +git config --global user.email "$EMAIL" +``` + +## Git init + +To initialize an existing directory as a Git repository you have to input the following command into a shell. +On windows your best bet is to launch a **git bash** shell by right clicking in the folder. +On linux you can just open a terminal, navigate to the desired directory and execute the command. + +```bash +git init +``` + +If you want to create a new directory with git version control inside it you run the following command. + +```bash +git init $DIR_NAME +``` + +## Git status + +List which files are staged, unstaged, and untracked. +This gives you a good overview of the current state of you repository and hints towards which files you can or should stage. + +```bash +git status +``` ## Git add -Stage all changes in **\** for the next commit. Replace **\** with a **\** to change a specific file. -> $ git add readme.md image.jpg +By staging files you put them in the list to be added to the next commit. +You can add one or more files at the same time. +Complete directories can also be added. + +```bash +git add readme.md image.jpg +``` ## Git commit -Commit your staged content as a new commit snapshot -> $ git commit -m "First Commit" +You commit your staged content as a new commit snapshot with the following command. +The message you include in the commit is fully up to you but as a general rule of thumb it should explain what the commit does. +For example: this commit *"adds pictures to the asset folder"* +Some projects have serious commit message [guidelines](https://www.datree.io/resources/git-commit-message), others not. -After doing this, you may fix the identity used for this commit with: +```bash +git commit -m "$YOUR_COMMIT_MESSAGE" +``` -> $ git commit --amend --reset-author +If the identity is not correct you can fix this this the following command. + +```bash +git commit --amend --reset-author +``` ## Git diff + Show unstaged changes between your index and working directory. > $ git diff