Use the git command line to upload the project to GitHub (take the R package as an example)

Today we will introduce how to use the git command line to upload projects to GitHub , which will involve some brief introduction to R package publishing. In fact, this note is because I want to introduce how to upload and share R packages for others to use . The steps for uploading projects on GitHub are the same, whether it is an R package or something else, so I just took this opportunity to introduce uploading in detail . The project is on GitHub !

If you need a video explanation, please go to Yixiaoman to
be uploaded.

We have successfully developed our own R package earlier. If we want to share it with others and allow others to use your package (blessings to the world!!!), then we can publish it! Generally we use two major platforms: CRAN and GitHub .

1 Publish your package on CRAN

Let’s start with a brief introduction to publishing your package on CRAN! I will introduce in detail later whether it is good to upload on GitHub!

Publishing a package on CRAN is a difficult step because it requires a lot of rigorous testing before it can be successfully released. In addition to passing these tests, you also need to give a detailed description of how the package works. These descriptions will be stored in the vignettes folder, which you can create in your main project directory.
After you have confirmed that your package runs well and records normally in the local simulation test, you need to create Build > Build Source Packagethe source package.
After creating the source code package, you can submit an application to publish the package on CRAN!

If your package is successfully released on CRAN, you will need to make sure to keep updating your package to fix certain bugs and/or add new features. If you do not update the package within a certain period of time, CRAN will abandon your package!

2 Publish your package on GitHub

Next is our focus today! Publish your package on GitHub!

Generally speaking, publishing your package on GitHub is relatively easy. The easiest way to publish a package on GitHub is to create a new repository, and then upload the xmypkgcontents of the main folder (we take the previously developed package as an example) to the repository and you're done!

Let’s take a look at the specific process!

First you need to create a new code repository (Repository) on GitHub. You can log in to GitHub and click the " " Newbutton to create a new repository.

Enter the create new warehouse interface, fill in the relevant information, and click " Create repository" to create it successfully.

After the warehouse is successfully created, you will enter this page.

In fact, we can see that this page has already told us what to do, and we will introduce it to you step by step later!

  1. First open a command line terminal and enter the root directory of your R package project. By git initturning it into a git repository (you can also create a new folder, turn it into a git repository, and then copy your project to this folder).

  2. By git add .adding all files to the git repository, .all files in the current directory are represented. If you only want to upload a certain file, you only need to git addadd the file name at the end, such as the one in the picture above git add README.md.

  3. By git commit -m "first commit"committing the project to the repository, the quotes can be filled with whatever commit message you want to use.

  4. Use the command git branch -M mainto create a new branch.

    You may be curious, why do we need to create a new branch?
    In fact, when using git, creating new branches can help us achieve better version control, parallel development and team collaboration in git projects. It provides a more flexible workflow, improves development efficiency, and helps keep the code base clean and stable. The specific benefits are as follows:
    a. Parallel development: By creating a new branch, we can perform development work on an independent branch without affecting the masterstable code on the main branch (usually a branch). This way we can work on multiple tasks at the same time, fix bugs, or try out new features without destabilizing the master branch.
    b. Version control: By creating new branches, we can easily manage different versions of code. For example, we can create a branch for each release so that we can make relevant fixes and adjustments on each branch while retaining the code state of each version.
    c. Feature development: Creating new branches can help us implement the feature development process. We can create a separate branch for each feature or functionality, and develop and test on this branch. Once the feature is developed and tested, we can merge that branch into the master branch.
    d. Team collaboration: Branches play an important role in team collaboration. Team members can work on their own branches and merge them into the master branch when complete. This way, everyone can develop and test code independently without interfering with each other.

  5. After creating the git warehouse on Github, we can associate it with the local warehouse. According to the prompts on the created git warehouse page, you can enter the URL of the warehouse you created in step 1 on the command line of the local git remote add origin <GitHub 仓库 URL>warehouse <GitHub 仓库 URL>. For example, in the example of this article, if we want to upload a development xmypkgpackage, we should enter the following line of command:

    git remote add origin https://github.com/hzyao/xmypkg.git
    
  6. Finally, git push -u origin mainpush the project in the local warehouse to the remote warehouse (that is, Github).

    Since the newly created remote warehouse is empty, you need to add -uthis parameter. After the remote warehouse has content, you only need to upload content from the local library next time git push origin main!

Note:

  1. If it is local, just follow the above steps and come directly! But if you are operating git on the server, make sure you have correctly configured git authentication (username and email address) before you can upload smoothly!
  2. There are size limits for uploading files as we introduced above. If you want to upload large files, you need to use Git LFS (Large File Storage, large file storage). The link below has what you want!
    Git Large File Storage | Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise.

After completing the above steps, you can use the command to install the R package on GitHub to install and use this package! as follows:

# 安装你的包
## 第一种方法
devtools::install_github("username/yourpackage")

## 第二种方法
remotes::install_github("username/yourpackage")

## 还有很多种方法,如果大家需要的话可以告诉我,我也可以专门出一期介绍!

# 加载你的包
library(yourpackage)

# 然后就可以顺利使用啦!

References

  1. How to use the git command line to upload projects to github_You are the sun-warming blog-CSDN blog_git command to upload projects
  2. How to create an R package and publish it on CRAN/GitHub – Reprinted - nkwy2012 - Blog Park (cnblogs.com)
  3. git commit command | Novice tutorial (runoob.com)

Guess you like

Origin blog.csdn.net/weixin_43843918/article/details/131407579