# Git Setup - Command Line ### INITIAL SETUP #### NOTICE - This is the HTTPS setup for git remote/upstreams. There's also a way to do this via SSH, but it's harder and unnecessary for most, and requires a far more complicated setup. 1. Install command line git as per "required things". 2. Open a command line. - For those of you who don't know what this is, you're going to suffer - `cmd.exe` in start menu, or better, `powershell.exe` 3. Navigate to the folder of your choice. For me, I just did it in `USERACCOUNT/Documents` but anything works, just remember where it is so you don't lose the repository. 4. Run `git clone https://github.com/Citadel-Station-13/Citadel-Station-13.git FOLDERNAME` - If you do not include a FOLDERNAME in foldername, it'll default to `Citadel-Station-13`. 5. `cd FOLDERNAME` to go into it once it's done 6. `git config user.name "YourGithubUsernameDoubleQuotesNeededIfItHasSpaces"` 7. `git config user.email YourGithubFakeEmailDoNOTUseYourRealEmail!!` - The "fake" email is avalable [here](https://github.com/settings/emails), it should looks like `24674964+FooBar@users.noreply.github.com`. Requires you to disable public email. 9. `git remote` - You should see one, origin. This should be something like this: `https://github.com/YourUsernameHere/Citadel-Station-13.git` 10. `git remote add upstream https://github.com/Citadel-Station-13/Citadel-Station-13.git` 11. Now test your setup - `git fetch --all` - You'll be prompted to enter your credentials for you account. - This should update you to the latest versions of your own fork, and Citadel's master repository. 12. If anything went wrong, contact us for help. ### `git fetch` This command is used for a variety of things, but for beginners, all you need to know is it updates a remote, which for you will either be `origin` (your fork) or `upstream` (Citadel Station). **Do this often.** `git fetch --all` or at the very least `git fetch upstream`. It is **crucial** you stay up to date as this is how git works. It won't work if you're constantly out of date and try to push changes to us. ### `git worktree` If you're like me and have too many projects and never know when to stop ~~wasting time~~ "multitasking", look into how to use `git worktree`. There won't be an explanation here as frankly you should use the git site or otherwise git help files for this, but it allows you to have multiple *working directories* with branches checked out on each **NEVER EVER CLONE THE REPOSITORY MULTIPLE TIMES INSTEAD OF USE WORKTREES. You are wasting your own disk space and internet for no reason. There is NO REASON to clone the same codebase more than once! ALWAYS USE GIT WORKTREES!** ### Making your first branch 1. Make sure you're `git fetch`'d to ensure you're up to date 2. The proper way to do this would be branching off your own master. The lazy way, which I am going to teach you here, is as follows. 3. Make sure your working directory is clean. - You are HEAVILY advised to install something like [posh-git](http://dahlbyk.github.io/posh-git)(powershell git), as that makes it much easier to see what's going on - You get this instead of having to manually check all the time.![](https://i.imgur.com/Tg4vor9.png) - First number is files added, second number is files changed, third number is files deleted. Red means unstaged changes, if it was green it would mean staged changes, the three bar equal sign means that commits are equal to the remote-tracked branch - You will not know what any of the above sentence means. Go learn git from a proper source, seriously. It's good to know and it's not that hard to learn, even for non-coders. This guide will only teach you how to make a pull request, and some common troubleshooting things. Seriously, go READ GIT FROM THE WEBSITE. 4. `git checkout upstream/master` - This puts your working directory on the latest master branch. 5. `git checkout -b "branchname"` - This checks out `branchname` to your working directory. **Since this specifies -b, it will make a new branch named `branchname` instead of trying to look for an existing one. This will fail if it already exists.** 6. Modify files 7. `git add *` Do this from the root directory of your folder (so just /Citadel-Station-13). This **stages** all changed files to be added to the next **commit** (set of changes) 8. `git commit -m "COMMIT MESSAGE HERE"` This commits changes to the history of the branch. Commit messages should be descriptive if possible. - DO NOT BE THIS GUY - ![](https://i.imgur.com/fnzX8pk.png) ### Pushing changes 1. Great, now you should see something like this (READ STEP 3) ![](https://i.imgur.com/8zEyzL7.png) 2. Now you need to **push** the changes 3. If this is your first time pushing the branch (**YOU WILL NOT SEE THE UP ARROW AND GREEN NUMBER IF THAT IS THE CASE!!**), you instead do `git push --set-upstream origin branchname` - This sets the target branch on GitHub to be the branch of the same name on your fork - Yes you can technically push to a different branchname by doing `HEAD:branchname` instead of `branchname` but **honestly don't bother messing with that, you don't need to be more overwhelmed than you probably already are.** 4. Otherwise, you just do `git push` 5. Done, congratulations ### Updating your branch - As long as you've been listening to me about using `git fetch` often, when you make a new branch, all you need to do is checkout our master branch and use `checkout -b` to create a new branch. - Updating an existing branch: - Ensure you've fetched our latest master branch - `git merge citadel/master`, replacing `citadel` with the name of your origin that's our repository. - If conflicts happen, see 'conflict resolution'. - **Do this often while working on a project if you can,** lest you stack yourself up a headache.