Skip to main content

Command Palette

Search for a command to run...

Git hub

Published
4 min read
Git hub
X

"I am currently a Software Engineering student at ALX. I'm passionate about technology and enjoy conducting research to find answers on my own. I have a natural inclination to ask 'WHY' more often than 'HOW'.

"While working on projects at ALX, I have acquired a wealth of interesting and diverse knowledge about software engineering and computer science in general. Therefore, I needed a place to store and save all this information, allowing me to refer back to it whenever I forget."

Simplest way to push your files(local repo) to remote repo(git) for the first time

To push your project to GitHub for the first time, follow these steps:

  1. Create a GitHub Repository:

    • Go to GitHub and log in to your account.

    • Click on the "+" sign in the top right corner of the page and choose "New repository."

    • Fill in the repository name, description, and other settings.

    • Click on the "Create repository" button.

  2. Initialize a Git Repository Locally:

    • Open a terminal or command prompt on your computer.

    • Navigate to your project's directory using the cd command.

    • Run the following commands to initialize a Git repository and connect it to the GitHub repository you just created:

        git init
        git add .
        git commit -m "Initial commit"
        git branch -M main
        git remote add origin https://github.com/your-username/your-repository.git
      

Replace your-username and your-repository with your GitHub username and repository name.

  1. Push Your Code to GitHub:

    • Now, push your code to GitHub using the following command:

        git push -u origin main
      

This command will push your code(all the files in that folder you initialized) to the main branch of your GitHub repository.

  1. Enter GitHub Credentials:

    • When prompted, enter your GitHub username and password(if you see the prompt, I don't normally get the prompts)
  2. Verify on GitHub:

    • Visit your GitHub repository in a web browser and verify that your code has been pushed successfully.

Congratulations! Your project is now on GitHub. Subsequent changes to your code can be pushed using git push origin main (assuming you are working on the main branch). Remember to replace main with the appropriate branch name if you are using a different branch.

git push origin main

When you run the command git push origin main, it assumes that you have a local branch named "main," and you are pushing the changes from this local branch to a branch with the same name on the remote repository referred to as "origin."

If there is no branch named "main" on the remote repository, Git will create a new branch with that name on the remote repository and push the local changes to it. The git push command creates a branch on the remote repository if it doesn't already exist.

If a branch named "main" already exists on the remote repository, the command updates the remote "main" branch with the changes from your local "main" branch.

It's important to note that the branch names should match between your local repository and the remote repository for a straightforward push operation. If you are working with a different branch locally and want to push it to a different branch remotely, you would specify the appropriate local and remote branch names in the git push command.

To specify different local and remote branch names when pushing changes, you can use the following syntax:

git push <remote-name> <local-branch-name>:<remote-branch-name>

Here, <remote-name> is the name of the remote repository (often "origin"), <local-branch-name> is the name of the local branch you want to push, and <remote-branch-name> is the name of the branch you want to create or update on the remote repository.

For example, if you have a local branch named "feature-branch" and you want to push it to a remote branch named "main" on the "origin" remote, you would use:

git push origin feature-branch:main

This command pushes the changes from your local "feature-branch" to the "main" branch on the remote repository named "origin."

Adjust the branch names accordingly based on your specific use case. This allows you to push changes from one local branch to a different branch on the remote repository.

Git hub pages.

How to host your projects(html,css,js) on github pages:

On your repo

  1. Click on Settings

  2. On the left side, scroll down and click on pages

  3. Under Build and deployment, click on none and select main, then click save.

  4. Go back to your project, or click on code on the top to go back

  5. Click on the green tick(success) close to the the name of your repo

  6. On the first line, click on details

  7. By the left, click on deploy

  8. Click on deploy to github pages

  9. Scroll down and click on complete job

  10. You will see a link, Evaluated environment url:. Thats your new website link