How to Upload Your Website to GitHub
Uploading your website to GitHub is an essential step to ensure proper version control, easy collaboration, and remote backups. Here's a comprehensive guide on how to push your site to GitHub, using GitHub Desktop and command line interface (CLI).
Before we start, make sure you have Git installed on your computer. If not, download and install it from here. Also, sign up for a GitHub account if you haven't already at github.com.
Setting Up GitHub Desktop
GitHub Desktop is a popular graphical user interface (GUI) for Git and GitHub. It makes version control easier by providing a visual representation of your changes.
First, download and install GitHub Desktop from its official page. Upon installation, sign in using your GitHub credentials.
Initializing GitHub Desktop
Open GitHub Desktop. In the welcome screen, click on 'Initialize a new repository'. Navigate to your website's root directory and click 'Select'.
This will create a local .git folder in your website's root directory, essential for tracking changes.
Committing Changes
GitHub Desktop lists all the files in your website directory. Any changes you make to these files will show up here. Click on 'Stage All' or select individual files to 'Stage'. Then, add a commit message in the 'Commit message' field and click 'Commit'.
Your changes are now version controlled locally. Next, we'll push these changes to GitHub.
Creating a Repository on GitHub
A repository (repo) on GitHub stores all your project's files and keeps track of revisions. Let's create one for your website.
Login to your GitHub account. Click the '+' icon in the top-right corner and select 'New repository'. Name your repository after your website and click 'Create repository'.
Adding a Remote to GitHub Desktop
Open your website's directory in GitHub Desktop. Click on the 'Remote' tab. In the 'URL' field, copy and paste your repository's URL (https://github.com/yourusername/your-repo-name.git). Click 'Add remote'.
Now, your local repository is connected to your remote repository on GitHub. You can push your changes using GitHub Desktop.
Pushing Changes to GitHub
In the 'History' tab, select the commit you want to push. Click 'Publish'. A small gear icon will appear next to the 'Remote' tab. Click on it and select 'Push upstream'.
Your website's files are now safely stored on GitHub. Whenever you make changes, remember to commit and push them to GitHub.
Using Command Line Interface (CLI)
If you prefer using the command line, follow these steps:
Open your terminal, navigate to your website's root directory. Initialize a new repository with the command 'git init'. Then, add your files with 'git add .'. Commit your changes with 'git commit -m "Your commit message"'.
Connecting to GitHub
Copy your repository URL. In your terminal, use 'git remote add origin your-repo-url'. Replace 'your-repo-url' with your repository's URL.
Verify your remote with 'git remote -v'. It should display your repository URL.
Pushing Changes
Push your changes to GitHub with 'git push -u origin master' (or 'main', depending on your default branch name). If this is your first push, you'll be prompted for your GitHub credentials.
Congratulations! Your website is now on GitHub. Whenever you make changes, use 'git push origin master' to push them to GitHub.
Remember to pull changes from GitHub if others contribute to your repository. Use 'git pull' to fetch updates and merge them with your local files.
That's it! You've successfully uploaded your website to GitHub. Now, every time you push, pull, or update, Git takes care of keeping your website safe and sound. Happy coding!