From a9eb0640cc4fe9f158da4c5ad2cfa4060d9e2c4b Mon Sep 17 00:00:00 2001 From: Ceikry Date: Fri, 7 Oct 2022 01:56:14 +0000 Subject: [PATCH] Create Git Basics --- Git-Basics.md | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 Git-Basics.md diff --git a/Git-Basics.md b/Git-Basics.md new file mode 100644 index 0000000..f13a5e0 --- /dev/null +++ b/Git-Basics.md @@ -0,0 +1,95 @@ +[[_TOC_]] + +## Installing Git & Git LFS +### Linux +Get it from your package manager, e.g: +``` +$ sudo apt install git git-lfs +``` +### Windows +Download and install Git from the [official website.](https://gitforwindows.org/index.html). + +**In the installer, you should make sure to select the below options:** + +
+Click to view options + +![image](uploads/5c985dd83eb9a7cdaa44909a28ba3698/image.png) + +![image](uploads/cd9aeb4b6da4e6aed57b1454e684a009/image.png) + +![image](uploads/e03d53cec397b31ef8af80f0edb03160/image.png) +
+ +## Fork this project +On the [homepage](https://gitlab.com/2009scape/2009scape) for this repository, click the fork button in the top right: +![image](uploads/7a7f1e55c5b7e0f9aca23a2a32e91f94/image.png) + +Now, name it whatever you like, e.g. leave the default of "Server" or call it "09 Dev", whatever you want really: + +![image](uploads/55973fca34bc1eae3a3a9fabc6f71341/image.png) + +Now, in the project URL "Select a namespace" dropdown, select your gitlab username, which in my case is Ceikry: + +![image](uploads/e20e0897ec9f2c25ad6b63597772e624/image.png) + +The **Project Slug** portion is what the url slug of your fork will be. E.g. since mine is 2009scape, my fork will be at gitlab.com/Ceikry/2009scape. If it was bababooey, the url would be gitlab.com/Ceikry/bababooey + +**Make sure to set the visibility level to public and click Fork Project:** + +![image](uploads/36f7f55d0f0a479c6b53dd9120aeb8d2/image.png) + +This forking process will take a while, but once it's done you'll be taken to your new fork of the project. + +## Clone the Project +Now that you have your own fork, you can get your fork cloned and set up locally! + +First, we need to get the link to **your fork.** On the page for your fork, e.g. gitlab.com/You/2009scape, click the "Clone" button, and copy the link provided in the "**Clone with HTTPS**" box: + +![image](uploads/3b752da1686c884d2e5f8b1d0644ae18/image.png) + +### Linux +Open up a terminal and cd to the directory you want the files to live in, and issue the `git clone ` command, where is the link you copied from before. + +### Windows +Open up Explorer and navigate to the directory you want the files to live in. Right click in the folder, and select "Git Bash Here" + +![image](uploads/3e2b15ca49c203a32b8dd082878f7822/image.png) + +Now, in the command window that opens, type `git clone ` then right click and paste the url you copied above, then hit enter. This will clone the repository into a new folder in the location you chose. + +## Adding 2009scape as your upstream +In the command/terminal window you have open, `cd` into the folder containing the cloned repo. If your repo is named `2009scape`, then you will `cd 2009scape` + +Now you want to issue the command `git remote add upstream https://gitlab.com/2009scape/2009scape` + +This will add an `upstream` remote reference to your git so that you can interact directly with the main 2009scape repository. + +## Creating Merge Requests +Merge Requests are how you get your changes into the main 2009scape repository. To create a merge request, go to the **page for your fork**, click the Merge Requests button on the left side of the screen, and then click the New Merge Request button in the top right. + +For the source branch on the left, select the branch that your changes exist in. On the right, make sure 2009scape/2009scape is the selected repository, and master is the selected branch. Now click Compare Branches and Continue, and fill out the Merge Request template provided to you. + +## Best Practices: Branches +Before you start making changes, **never make changes on the default branch, aka master.** +You should always create a branch for each feature you add/bug you fix, etc. +You can create a new branch using `git checkout -b branchname`, and you can move between branches using `git checkout branchname` (note the lack of -b) + +## Best Practices: Updating Your Fork +Updating your fork doesn't have to be painful, in fact assuming you follow the best practices for branches outline above, it's super easy! With a command(Git Bash)/terminal window opened up to your 2009scape folder, just do: +``` +$ git checkout master +$ git fetch -ap upstream +$ git pull --ff-only upstream +$ git push --force origin master +``` +And just that easily, your fork is completely up to date! +Now, the next thing you should do is ***rebase*** your branches. +Let's say you had a branch open for cider, called `cider`. +Simply do: +``` +$ git checkout cider +$ git rebase master +$ git push origin cider +``` +And now your `cider` branch is updated onto the changes present in the updated master branch. \ No newline at end of file