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

Why isn't my CSS float behaving as I anticipated?

I'm currently working on a website and facing an issue. The CSS Float property is not behaving as expected. Here is my HTML Code: <div class="slider-menu"> <div class="slider-box"> <img src="agac.jpg"> & ...

What are some effective design principles for creating REST APIs in expressjs?

To streamline my code organization, I made the decision to create a methods folder. Within this folder, I store individual JavaScript files for each URL endpoint (such as website.com/billings). //expressJS configuration... const billings = require('. ...

Function that returns an array

Hey there, wondering about variable scope in closures! I've come across a lot of questions on this topic but haven't found the solution to my issue. Here's the code snippet: var teams = []; var players = []; var getRoles = function(roleL ...

Transferring an array from PHP to Javascript using GET method

Can someone help me figure out how to pass an array to Javascript after it sends a GET request to PHP? I've got the data sending and retrieving down pat, but now I'm stuck on how to send the data back as an array. Here's what I have so far: ...

Posting and deleting data in AngularJS using HTTP requests

Incorporating both angularjs and c# webapi in this situation. My approach involves calling the webapi from angularjs and passing a json array. Here is the Angularjs code snippet: factory.delete = function (json) { var url = 'myUrl'; ...

Encountered a problem during the insertion of data into the database through ajax and php

An issue is being encountered while trying to insert data into a database using Ajax, PHP, and jQuery. The code works smoothly on a localhost environment, but upon uploading it to the server, an error occurs. $('#sunsubmit').click(function(){ ...

Creating a custom jQuery plugin with an undefined JavaScript function

Having some trouble with my custom jQuery plugin. Browsers are throwing errors saying a function inside the plugin is undefined. Could someone take a look at my code and spot any mistakes? (function($){ $.fn.myCustomPlugin = function( ) { return ...

The Kendo Date Picker is failing to update properly when the k-ng-model is modified

I am facing an issue with my code involving two date pickers and one dropdown list. I want the date pickers to change based on the selected item from the dropdown list. Here is the relevant portion of my code: $scope.toolbarOptions = { i ...

Retrieve information from a controller and pass it to a Component in AngularJs

Having an issue with passing data from a controller to a component in AngularJs. The data is successfully passed to the template component, but it shows up as undefined in the controller! See below for my code snippets. The controller angular.module(&a ...

Error message: The protocol "https:" is not compatible with this function. Please use "http:" instead

I decided to use IBM Bluemix for my school project, where I am working on creating a web service. For my project, I need to fetch JSON data from an API in order to utilize the provided information. Currently, I am utilizing the http get method to retrieve ...

Loading of iframes occurs only after receiving the content sent through the postMessage function

I have a scenario where an iframe is used to receive information through the contentWindow.postMessage function in order to log in to a page that I am creating. However, I am facing an issue where the page loads before the contentWindow.postMessage message ...

A simple way to deactivate a React component (or the onClick event itself) using the onClick event

I have come across similar inquiries, but unfortunately, none of the solutions provided seem to work in my particular scenario. I am hopeful that someone can shed some light on what might be causing the issue. In my ReactApp, there are 3 card components t ...

Combining two arrays of objects using JavaScript

I am working with two arrays of objects that look like this: objects [ { countMedias: 2 }, { countMedias: 1 }, { countMedias: 3 }, { countMedias: 1 }, { countMedias: 2 } ] listePlayliste [ { nom_playlist: 'bbbb' }, { nom_playlist: &apo ...

The child element fails to increase in size if the parent element has a minimum height specified

I'm having trouble getting min-height to work properly. The issue is that my child element doesn't inherit the height of its parent, so it's not setting its own height correctly. How can I resolve this? #middle_Wrapper { width: 100%; mi ...

The web typography appears fuzzy or has incorrect thickness, lacks consistency across pages and even within a single page

The font (ProggyCleanSZBP.ttf from 1.1.5 release) appears to be intermittently thick and blurry. If you compare with , you'll notice that the latter displays as desired in most cases, but there are instances where the issue occurs, such as the first ...

Can Next.js 13 components maximize performance by utilizing server and client components simultaneously? What is the best approach to achieve this?

Introduction Currently, I am exploring server and client components in Next.js 13 and looking to incorporate them into my project. One of the key features is a container component that utilizes react-intersection-observer to track which section is visible ...

Exploring the possibilities of reading and writing data in localStorage?

Just starting out with Phonegap, jQuery Mobile, and HTML5 - so please bear with me as I navigate through this learning process! I'm having an issue and could use some help. When trying to use a variable from localStorage, the screen remains blank whe ...

It is not possible to highlight the text that appears in the title of the tooltip in React MUI

Within my react application, there is a component that utilizes the code snippet below: <FormControlLabel labelPlacement="top" control={ comp?.manualInput ? ( <TextField name="price" type= ...

What is the correct method for redefining properties and functions in Vue.js?

Is there a proper method for overriding methods using mixins in Vue.js? While it's possible to mimic inheritance with mixins, what if you only want to extend certain props without completely replacing the entire prop value? For example, let's sa ...

Avoiding the Popover Component from Covering the Screen When the Menu Component Opens in React Material UI

I have implemented a Menu component to display a menu upon hovering over an element. However, I have encountered an issue where the menu includes a Popover component that opens up and covers the entire screen as an overlay, preventing interaction with th ...