3 To Create Github Repository and Pull it to your Local Machine
4 Creating a GitHub Repository
Follow these steps to create a new GitHub repository:
- Sign in to GitHub: Go to GitHub and sign in.
- Create a New Repository:
- On your GitHub homepage, click the + button in the upper right corner, then select New repository.
- Fill out the repository details (repository name, description, visibility) and click Create repository.
- Initialize the Repository:
- Optionally, check the box for initializing the repository with a README file.
- Add
.gitignoreor license files if needed.
After completing these steps, you’ll have a GitHub repository URL, which will be used in the next step.
4.1 Cloning the Repository to Your Local Machine
To copy (clone) the newly created GitHub repository to your local machine:
Copy the Repository URL: On the repository page, click the green Code button and copy the HTTPS URL.
Change the current directory if needed: Open your terminal (or Git Bash on Windows) and run the following command:
cd <directory path> # Change the current directory
- To go to a specific directory:
cd /path/to/directory
- To go to your home directory:
cd ~
- To go back to the previous directory you are in:
cd -
- To navigate to a directory inside the current directory: If you are already in /home/username, and you want to go to Documents, just type:
cd Documents
- To go up one directory (move to the parent directory):
cd ..
After changing the directory, you can verify your current location by running:
pwd #This command displays the present working directory.
4.2 Clone your remote repository to your local machine
- Clone the Repository: Open your terminal (or Git Bash on Windows) and run the following command:
git clone <repository-url> # That you copied as described above
You now have a local copy of the repository on your machine.
4.3 Pulling Changes from GitHub
Once your repository is set up, you may want to pull changes from the remote repository to your local machine. This is how to do it:
git pull
This command fetches the changes from the remote repository (on GitHub) and merges them into your local copy.
If you want to set or change your local branch (named master or main) to its upstream tracking to a remote branch, you can run the following command:
git branch --set-upstream-to=<remote>/<branch> master
The command git branch - -set-upstream-to=<remote>/<branch> master is used to set the upstream (or tracking) branch for your local master branch to a specified remote branch. Here’s a breakdown of what each part of the command means:
Breakdown of the Command
git branch: This is the command used to manage branches in Git.
- -set-upstream-to: This option sets the specified remote branch as the upstream branch for the local branch. This establishes a tracking relationship between the local branch and the remote branch, making it easier to pull and push changes.
<remote>/<branch>:
<remote> refers to the name of the remote repository (commonly origin, which is the default name when you clone a repository).
<branch> refers to the name of the branch on the remote repository that you want to track.
master: This is the name of the local branch for which you are setting the upstream branch. In this case, it specifies that the local master branch will track the remote branch you defined.
If you would like to rename the local branch (master) to resemble remote branch (main). Use the following command:
git branch -M main
To render into HTML document, run the following command:
quarto render document.qmd --to html # Replace document.qmd with the name of your Quarto file.
If you want Quarto to automatically open the rendered HTML file in your browser, you can add the –open option:
quarto render document.qmd --to html --open
Note: Make sure to enclose the file name in quotes if it contains spaces
4.4 Conclusion
In this guide, you will learned how to create a GitHub repository, clone it to your local machine, and pull changes. These are essential steps for version control and collaborating on code with others.
For more advanced Git commands and GitHub workflows, consult the official Git documentation.