Github Questions!

I’m new to Github and don’t know a lot of how it works. For example, I can’t seem to get rid of old junk in my master branch thingy.

Github has their own tutorial that will teach you how to use it, sololearn also has free courses for alot of things coding/modding related edit** adding a link to help narrow your search - https://product.hubspot.com/blog/git-and-github-tutorial-for-beginners

So there’s github, which is a pretty set of web pages, and there’s git, the underlying command line interface version control system that github is providing a limited graphical user interface for. I apparently don’t really know how to use github, but I do know how to use git.

So first off: git is an open-source, freely available version control system with a command line interface. There’s a lot of tools to make using git simpler, but I’m going to stick with the basics. git is available for all systems - you just need a command line interface to get it going. There’s a bunch of ways to do that - if you’ve got a Linux system, you just open up a command terminal; if you’re using Windows, I really recommend installing cygwin (cygwin.org) because that gives you a Linux work-alike interface. (I’m a professional Linux programmer so there may be some pro-Linux bias in this discussion; Windows people are welcome to provide better alternate solutions).

git works on three things: repositories, branches, and commits. A repository is a collection of branches consisting of serial lists of commits, where each commit is the change in the files under version control from the previous one. Your github repository is one repository, but you can have others and use push and pull to transfer commits between them.

So the first thing you want do after you get access to git on a command line interface is to clone your github repository onto the same computer that you’re running git on. Go to your github page, hit the green “clone or download” button, and then type "git clone " folllowed by the URL they give you.[1] This will download a copy of your repository to your computer.

You can change directory into your new repository, and use the git command line to manipulate the local repository. For instance (I’m looking at your repository on github now, btw), you could do “git reset --hard 47d21c” and that would reset your local repository to only include your first two commits[2]. Then you could push your local repository back up to the github repository by doing “git push --force”, which will overwrite the github repository with the branch history of your local repository.

Alternately, another thing you could and possibly should do is stop editing your mod as a stand alone project, and instead make it a branch of a fork[3] of the main C:DDA repository. The way you would do that is:

  1. Go to https://github.com/CleverRaven/Cataclysm-DDA
  2. Hit the “Fork” button and now you have your own version of C:DDA.
  3. Clone that to your local machine with the “Clone or Download” button.
  4. Go into your new C:DDA directory and run “git remote add upstream https://github.com/CleverRaven/Cataclysm-DDA”, then “git fetch upstream”, then “git checkout -b upstream-master upstream/master”. That will set your local repository to follow changes in the main C:DDA repository.
  5. run “git checkout -b reds-odd-adds upstream-master” to create a new branch based on the latest upstream commit.
  6. go back to your Reds-Odd-Additions repository at github, and copy your commits back to your local C:DDA repository. use “git add” to add changes to a commit, and “git commit” to commit your changes. Just put your stuff where it belongs under data/mods/ .

If you’re feeling really adventuresome, you can compile C:DDA on your local machine - which is easy to do under Linux and a pain under Windows (or at least, I haven’t gotten it working but haven’t tried hard).
Alternately, you can just download the latest verison for your system type and copy the executables into your local C:DDA repository, which is how I actually play C:DDA on Windows.

The reason you want to go through this hassle is that you can periodically pull in all the changes from upstream into your local repository, keeping your game up to date without requiring that you move your save files around or mess with moving your mod.

But that’s a discussion for a slightly later date.

[1] You probably want to select the “use SSH” option, which means setting up your github account to allow SSH. See https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
[2] Your entire repository consists of 2 branches with a total of 3 commits. How much old stuff are you trying to get rid of here?
[3] A fork is just a new, private version of a project, and is often used to develop changes and then push them back to the main project.

2 Likes

Gitkraken is also a free pretty GUI that does everything git does but the benefit of being beginner friendly. Works on all OS IIRC. Alot of the features are available in a right click drop down menu.

That I dont get. But I would like to lesrn git

What is the upstream-commit? Where is the new branch created?

In general, upstream is the development branch of whatever project you’re working on. So the official C:DDA repository is the upstream in this case, and the most recent commit is the latest upstream commit. On June 18th, that’s commit 9844ca2 (https://github.com/CleverRaven/Cataclysm-DDA/commit/9844ca23ec00315f757da76e6969ba7149ab88fd) but it changes as new commits are added to the upstream repository.

The new branch is created in your local repository (the one you created by cloning the github repository) but you could use git push to push it back to the github repository.

Okay, the master branch of Reds-Odd-Additions has the following commits (most recent at top):
eeedb40 Add files via upload
479d21c ROA Version 0.0.1 (Early Alpha)
6ea6056 Initial commit

Each commit has a bit of metadata that points to the previous commit, and a branch is just a bit of metadata pointing to the most recent commit in the branch. git can then move backwards from each commit to its predecessor to get a list of all the commits in the branch.

git reset simply sets the branch metadata to point to a new commit. As your repository currently exists, the master branch points to commit eedbd40, and that git reset command would make it point to commit 479d21c instead - which has the effect of making commit eeedb40 disappear from the branch and leaving you with only 479d21c and 6ea6056 in the branch.

Does that make sense to you? If not, what else would you like to know?