diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3606de8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +my_projectlog.md \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..607525b --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [2026] [nesch] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/docs/cheatsheet.md b/docs/cheatsheet.md new file mode 100644 index 0000000..01af260 --- /dev/null +++ b/docs/cheatsheet.md @@ -0,0 +1,9 @@ +# Git cheat sheet + +Below is a Git cheat sheet with commonly used Git commands. + +![Git cheat sheet](../images/git_cheatsheet.png) + +## Source + +The cheat sheet image was obtained from https://raw.githubusercontent.com/hbons/git-cheat-sheet/master/preview.png \ No newline at end of file diff --git a/docs/commands.md b/docs/commands.md new file mode 100644 index 0000000..8efa3fc --- /dev/null +++ b/docs/commands.md @@ -0,0 +1,135 @@ +# Commonly used commands in git and GitHub + +## Adding a ssh key for a new computer you wanna use Github on + +1. Create a new ssh key for the new computer + +`ssh-keygen -t ed25519 -C "your_email@example.com"` + +2. copy the public ssh key to clipboard + +3. Paste it into the ssh key section on Github + +## Configurate git in new repository + +1. Give username + +`git config --global user.name "Your Name"` + +2. Give E-mail adress + +`git config --global user.email "email"` + +## When you start a new repository locally + +1. Make a folder where the project will be stored + +2. In the commandline go to the folder + +`cd ` + +3. Initialize git + +`git init` + +4. Save your first file into the folder + +5. Add file to repository + +`git add ` + +6. Commit together with a meaningful message + +`git commit -m ` + +## Connecting your local repositroy to GitHub for the first time + +1. Add the repository to you GitHub account using a ssh adress + +`git remote add origin ` + +If you accidentally added a wrong address, you can remove with this command + +`git remote remove origin` + +2. Set the name of the main branch + +`git branch -M ` + +3. Push your changes to GitHub while setting upstream + +`git push --set-upstream origin ` + +## Check git status + +Shows branch you are in and potential untracked changes + +`git status` + +Shows history of all changes together with ID + +`git log` + +Compare commits + +`git diff` + +`git show` + +## Recover to a previous state + +Recover to a previous state: Removes changes (means also deleting IDs so you can no longer access) + +`git reset` + +Reverts to previous state: Adds revert as a new head which means all changes are still tracked + +`git revert` + +Rewrite last commit message + +`git commit -amend` + +Go to a specific ID (!Warning tracks will not be saved unless you attach the new branch to main) + +`git checkout ` + +Attach branch + +`git switch -c ` + +## Alternative history + +Make new branch + +`git branch ` + +Go to specific branch + +`git checkout ` + +Merge branches + +`git merge ` + +Remove branch + +`git branch -d ` + +## Tagging + +To highlight good versions + +`git tag ` + +`git push --tags` + +## Other git commands + +Save temporarily uncommitted changes without creating a commit + +`git stash` + +Modify you most recent commit without creating a new one (used to fix commit message, remove unwanted files or add forgotten files) + +`git commit --amend` diff --git a/docs/concepts.md b/docs/concepts.md new file mode 100644 index 0000000..618c75f --- /dev/null +++ b/docs/concepts.md @@ -0,0 +1,50 @@ +# Git concepts + +Git is a version control software to track changes in files over times which runs **locally** in contrast with github which is an **online** platform to store (backup) your Git repositories. This will allow you to easily share and collaborate with others. + +## Conceptual areas + +1. Developing area: directory where the project is developed. +2. Staging area: in this space we organise files before a commit e.g. we want to commit file A and B together because they are related so we will put them both in the staging area. +3. Local repository: this is .git file where the git software manages all the versions that are committed. + +## Commit messages + +Adding a commit message is obligated, without it you cannot commit. Good commit messages will help you trace back what changed more easily. + +Be as descriptive as you can. You can use the following questions to write a meaningful message: + +- Why was it changed? +- How does this address the issue? +- Are there any effects due the change? +- Are there any limitations of the change? + +## From local to remote + +- SSH key: A way to securely connect to a remote computer/location/server. We add it to github in the settings for ssh key. +- How to create an empty remote repository on github: add a new repository on github, give it a nice name, don't add any files and follow the instructions to connect with the local +- Before we can backup our local repository we need to connect it to the remote repository. This is done by adding the origin of the remote repository by using remote add origin. Setting up this connections (bridge) between both is only done once. +- I should always synchronise the changes. Git push will send changes to my collaborators and the remote repository while git pull will send the changes from my collaborators or online changes to to my local repository. + +## README file + +This is a detailed description of the project, usage and installation. If it is named like this, it will automatically be the first page the user sees. + +## .gitignore file +A list of files that should be ignored. Usually this is data, backups, intermediate files and confidential files. You can also use regex to ignore files that contain the certain pattern. If you put .gitignore itself in the file, this will also be ignored. + +## Branching & checkout + +To experiment risk free we can use branches. A new branch will have an independent timeline. It could be useful for debugging and testing especially when collaborating. You can move between the branches by using git checkout. +TIP: put the initial of the person who's working the branch in the name. + +### Mirror effect +When using multiple branches, your environment becomes dynamic. + +## Tagging +This is a way to highlight good versions (states/commits). It doesn’t matter in which branch. This way you don’t need to remember the commit id, but you can just give it a name. This is used e.g. for: +- A good version +- A version for a release +- A specific feature +- Experiment risk free +- ... \ No newline at end of file diff --git a/examples/example_conflicts.md b/examples/example_conflicts.md new file mode 100644 index 0000000..2ddf575 --- /dev/null +++ b/examples/example_conflicts.md @@ -0,0 +1,25 @@ +# Examples of conflicts +Document examples of conflicts and their resolution here. + +*Hint: git usually tells you what needs to be done when an issue arises. Make sure to read the output in the terminal and follow the steps suggested.* + +## Example 1 + +### Conflict situation +I am trying to push some changes to the remote repository but I get an error: + +``` +$ git push +To https://github.com/neeschilling/project_github_microcredential.git + ! [rejected] merge_branch_2 -> merge_branch_2 (fetch first) +error: failed to push some refs to 'https://github.com/neeschilling/project_github_microcredential.git' +hint: Updates were rejected because the remote contains work that you do +hint: not have locally. This is usually caused by another repository pushing +hint: to the same ref. You may want to first integrate the remote changes +hint: (e.g., 'git pull ...') before pushing again. +hint: See the 'Note about fast-forwards' in 'git push --help' for details. +``` + +### Conflict resolution +Because we were both working on the same file, the person trying to push last will get an error. You first need to check which changes were made by both and which to keep. This can be done with the command `git config pull.rebase false` after which you peform `git pull`. +This will now open the file involved in editing mode you can see the conflicting changes, decide what to keep and what not (or keep everything) after which you can add, commit and push the final changes. \ No newline at end of file diff --git a/images/git_cheatsheet.png b/images/git_cheatsheet.png new file mode 100644 index 0000000..91786b0 Binary files /dev/null and b/images/git_cheatsheet.png differ