🐈‍⬛

How to Use GitHub Step1: Create repository

2024/05/07に公開

If you haven't read the article about git, I recommend reading it first.

1. Create remote repository

First, create a remote repository in github. We can make it from a plus button on the top right.

In addition, generate an access token at the developer's tab(bottom of the left tab group in setting page) on the settings page. (recommending selecting repo)

2. Create local repository

Next, we make a local repository in our pc by git init, and add it to the remote repository:

git init
git remote add <remote repository name> <remote repository URL>

Typically, origin is used for the name of the remote repository.

・example

git remote add origin https://<user_name>:<access_token>@github.com/XXXX/XXXX.git

This connects the remote repository to the local repository.

Additionally, please make some files in the local repository and add/commit them as preparing(git add . and git commit -m "comment").

git add .
git commit -m "comment"

3. Push to remote

Refreshing remote repository to local repository in this code:

git push -u <repository_name> <local_branch_name:remote_branch_name>

If both branch names are the same, we can omit remote_branch_name.
When the error remote: Invalid username or password. occurs, please delete the remote origin by git remote remove origin and try add again by modifying <remote repository URL>.

・example

git push -u origin main

This is called push, Inversely, bringing content from a remote repository is called pull.
Option -u means to set origin as an upper branch of the local main branch, after this, we only have to execute git push without the need to specify the branch name each time when we want to push.

At this point, repository creation is complete.

4. Clone repository

Here, I introduce a way to get a repository that already exist. It is simple and not necessary remote add with url taken from GitHub repository page, we have to only use the clone at the directory where we want to create a repository.

git clone https://<user_name>:<access_token>@github.com/XXXX/XXXX.git

*user_name is a string that is at the end of the home GitHub page URL.

By this command, the default branch of the remote repository is downloaded to a local directory and connects both repositories automatically. (default repository is confirmed at setting in github.)

5. Pull repository

If you want to update a local file with a reflected remote repository after clone, you can use pull

git pull origin main

or fetch and merge. pull is created by combining fetch and merge, so below means the same as pull.

git fetch origin
git merge origin/main

6. Reset

Execute the following code to reset the git.

rm -rf .git

Summary

This time is over, I explain more detail usage of git command with github in the next article.
thank you for reading.

Next: Part2 is published!

Discussion