Exploring the World of Github on Windows: Understanding the 'master' and 'gh-pages' Branches

I have developed a simple jQuery plugin and uploaded it to Github. I am using both the Github website and Github for Windows to manage this project.

However, when I try to include the .js or .css files from Github using the Raw links, my browser fails due to the MIME-type being set as plain/text.

After spending hours researching, I understand that creating a project page (gh-pages branch) is the first step to make these files accessible for linking. But most of the guides I found assume a UNIX-based system or require console-based tricks:

References: GitHub, SO, SO

There must be a simpler way to share these source files for inclusion. After automating the creation of a 'project page', I'm now faced with another branch that appears to lag behind the 'master' branch, leaving me confused on the next steps. It's unclear why I need to create an additional branch in the first place, making this process unnecessarily complex.

To summarize:

  • Created a new branch in Github (using Windows app and website)
  • Able to manage and update files without issues
  • Cannot include .js and .css files using 'raw' links
  • Desire to include these files on a page
  • Hoping to achieve this via Github for Windows or the website itself

If anyone can provide guidance on this matter, I would greatly appreciate it, and I believe many others would benefit from a clear solution as well.

EDIT: Referencing a popular Github project where files are easily accessible through Github:

Select2:

EDIT2: I now understand the purpose of creating a separate branch to share files, as Github's source control is not intended to act as a CDN. The project page serves as a public platform for hosting files, so the question now shifts to how I can transfer files from the master branch to the gh-pages branch. I simply want access to the directory structure to manually place the files there, without worrying about automation at this point. Despite being "10 commits behind," syncing my branch with Github Windows shows no content to retrieve from the gh-pages branch. What could be causing this?

EDIT3: Added my own findings and solutions to the situation thus far.

Answer №1

There is an abundance of resources available for those utilizing console-based Git software, but finding information on exclusively using Github Windows proved to be a challenge. However, here is the solution:

Here's a breakdown of the process:

  • Start by creating a project page following the instructions provided here:

  • Unfortunately, only console-based solutions are offered for obtaining a local copy. Here's how you can navigate this using Github Windows (assuming your project is named myproject, comprised of myproject.js and myproject.css).

  • Once the page is created (which may take a few minutes), launch Github Windows.

  • In Github Windows, access the repository for your project. From the top menubar, select "master" and switch to the "gh-pages" branch - view this helpful example from StackOverflow.

  • Upon switching branches, the folder

    C:\Users\YourName\Documents\GitHub\myproject
    will display the files for the "gh-pages" branch. Returning to the "master" branch in Github Windows will reconfigure the folder structure accordingly. This distinction initially caused confusion for me, as directories for both branches cannot be viewed simultaneously.

  • Choose the "master" branch within Github Windows.

  • In Windows Explorer, copy myproject.js and myproject.css to a separate directory (e.g., c:\temp).

  • Return to Github Windows and select the "gh-pages" branch.

  • In Windows Explorer again, move the previously copied files from c:\temp to a new location like

    C:\Users\YourName\Documents\GitHub\myproject\myproject-1.0\

  • Head back to Github Windows, where you'll observe "2 files to be committed." Enter your commit message and click 'Commit'.

  • Then, click 'Sync'.

  • You can now utilize these files in your webpages by referencing a URL such as:

    http://yourname.github.io/myproject/myproject-1.0/myproject.js

Undoubtedly, this method proves to be quite cumbersome when frequent updates to source file(s) are expected. An automated approach would certainly be more convenient. There's a solution addressing this on StackOverflow here, albeit involving UNIX-based scripting which may not be feasible for all users. If a more efficient way using solely GUI-based tools emerges, myself and others would eagerly welcome it.

EDIT: It's worth noting that this solution deviates from Github's intended workflow; clicking on the "gh-pages" branch on the Github website reveals it as being "5 commits ahead and 11 commits behind" the master branch, notwithstanding the identical files present. As such, I remain open to alternative GUI-based approaches to address this issue promptly.

Answer №2

My experience with Git(hub) software for Windows has been less than smooth, in fact, it's probably the buggiest tool I've ever used (and that says a lot, considering Windows itself). Trying to get anything done with Git on Windows was always a struggle for me.

But, let me help you out with your question. If you open a command prompt and type in

git checkout -b gh-pages

(if there's an error about branch gh-pages already existing, just remove the -b.)

it will switch the branch for you. Then, you can open notepad++ or your preferred text editor (you might need to do this from the terminal, but I'm not entirely sure), add the file you want, and then enter this command (in cmd):

git add .

This will add all files in the folder to Git recursively.

git commit -m "Add file for easy user download"

This includes the commit message.

git remote add origin <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b4d3d9c5e1d3d9c5dddac9dee2dfd3">[email protected]</a>:yourusername/yourrepository.git

This connects your Github repository so you can push your changes to it.

git push origin gh-pages

Now, you've successfully pushed your changes to Github!

If you're interested, you may want to check out this resource on Git branching.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Columns with adjustable widths

I am looking to create a layout with 3 columns (which may change, could be up to 4) that are all flexible width and fill the screen. Does anyone know if this is possible using CSS? Basically, I want three blocks lined up horizontally that take up the enti ...

JavaScript is unable to identify the operating system that is running underneath

Even though I am on a Windows system, the browser console is showing that I am using Linux. function detectOS() { const userAgent = navigator.userAgent.toLowerCase(); if (userAgent.includes('win')) { return 'Windows' ...

Guide on using JavaScript to extract and display a random text from a datalist upon clicking with the onclick event

Is there a way for a JavaScript function to select a random sentence from a datalist within the same file and display it upon clicking a button with an "onclick" event? I'm new to JavaScript and seeking the simplest solution. Can anyone provide an exa ...

Dealing with NULL values in a Postgresql database

In the web-survey I created, users are able to select their answers by using radio buttons. To determine which buttons have been selected, I utilize javascript. I have not pre-set any default states for the buttons, allowing users to potentially leave ques ...

Challenge with Vite, React, and MSW Integration

Having some trouble setting up MSW in a React application. It's unusual for me to come across issues like this. I've configured an environment variable VITE_MOCK set to true when running the yarn start:mock command. This should enable API mocking ...

Display buttons when hovering with React

Seeking assistance with implementing functionality in a React application where buttons for editing and deleting display only when the mouse hovers over the corresponding row. Currently, the implemented code displays these buttons in all rows on hover. Sn ...

Focus on an empty <input> tag with just the type attribute

In what way can React Testing Library be utilized to isolate a blank <input> element that solely possesses a type attribute? For instance, consider an input field that will eventually have attributes added dynamically, much like the surrounding labe ...

Approach to converting between metric and imperial measurements for weight and height

When prompting users to enter their weight, it's important to consider both metric and imperial units. One convenient approach might be to provide a dropdown menu for users to choose their preferred unit of measurement before filling in the correspond ...

Tips for dodging drawn-out sequences of periods

When working with nested objects using dot notation, it can be tedious to constantly check if each previous object exists. I'm looking for a solution that avoids lengthy if chains like if (a && a.b && a.b.c && a.b.c[0] ... ) ...

Eliminate the unnecessary gap below the image

I have noticed that there is too much space beneath an image on my website. I have tried checking for extra tags, but I suspect that it might be controlled in a css file. Could someone please help me identify which part of the css is causing this extra ...

Issue locating the prettyPhoto() function in ASP.net Jquery

I've been stuck on this issue for a while, so I thought I'd reach out to someone with more expertise. I'm working on a .NET website and trying to implement the prettyPhoto Jquery plugin. I have included the Jquery main library and the Pretty ...

Retrieve Browser Screen Width and Height using MVC3 Razor in the View

I am facing a challenge on my website where I need to generate a Bitmap dynamically and ensure it is rendered according to the width and height of the browser so that there are no overflow issues on the page. Although I have successfully created an image ...

What is the best way to compare two times in the hh:mm AM/PM format?

I need to handle times in the format of hh:mm AM/PM generated by a specific plugin, and perform comparisons on them using jQuery/javascript. When a user manually inputs a time, I require the text in the textbox to automatically adjust to hh:mm AM/PM with ...

Is it possible to transfer a massive number of files using node.js?

I need to asynchronously copy a large number of files, about 25000 in total. I am currently using the library found at this link: https://github.com/stephenmathieson/node-cp. Below is the code snippet I am using: for(var i = 0; i < 25000; i++ ...

Adjusting the background color of an individual element within a grid using CSS

<div id="56c46f8385953" class="mg_box mg_pre_show col1_3 row1_3 m_col1_2 m_row1_3 mgi_14 mg_pag_1 mg_gallery mg_transitions mg_closed " rel="pid_14" mgi_w="0.333" mgi_h="0.333" mgi_mw="0.5" mgi_mh="0.333" > <div class="mg_shadow_div"> ...

To see website changes, refreshing with Ctrl + F5 is necessary in the browser

I have a simple website that uses only HTML and CSS. Whenever I upload new files to the site, they do not appear in the browser until I perform a hard refresh by pressing CTRL + F5. Does anyone have any suggestions on how to fix this issue? ...

Is there a setting causing Webpack to not rebuild when there are changes to the CSS?

I have configured postcss-loader and style-loader on webpack, and I am using webpack-dev-server. However, every time I make changes to the CSS, webpack does not rebuild automatically. The script for webpack dev server that I use in npm scripts: webpack-d ...

Firefox does not display the line headings on the sides

Hey everyone, I'm facing a compatibility issue with CSS and Firefox today. When I go to my website www.fashoop.com, you'll notice some header lines on the sides. Here's an example in Google Chrome: (GOOGLE CHROME EXAMPLE) COLOR BLUE AN ...

Is it possible to change XML using Ajax technology?

Is it possible to update a value in an XML file using JavaScript/Ajax? I've managed to access the XML file with Ajax and utilize its values in my script. Now, I want to send any updates made by the script back to the XML file on the server using Ajax ...

Tips for aligning an element vertically when it has a float using CSS or JavaScript

I am struggling with centering the image within the article list loop I created. The code snippet looks like this: <article class="article <?php if($i%2==0) { echo 'even'; } else { echo 'odd'; } ?>"> <section class ...