Gitlab basic Operations-upload, download, library migration/backup and recycling/renaming

Source: Internet
Author: User
Tags using git version control system

Gitlab basic Operations-upload, download, library migration/backup and recycling/renaming

  1. Gitlab Basic Concepts
    Gitlab is a Web-based Git repository management tool with wiki and issue tracking capabilities. GitLab is developed by GITLAB Inc. to use open source licenses.
    GitLab was developed by Ukrainian programmers Dmitriy Zaporozhets and Valery Sizov. It is written by Ruby. Later, some parts were rewritten in the go language. As of December 2016, the company had 150 team members and more than 1400 open source contributors. Gitlab was Ibm,sony,jülich center,nasa,alibaba,invincea,o ' Reilly media,leibniz-rechenzentrum (LRZ), CERN, SpaceX and other organizations used.
    ---above: wikipedia
  2. Gitlab Library Creation

    Click "New Project"

    Follow the steps above and finally click "Create Project"
  3. File Upload
    在客户端上(mac本的远程终端上)进行如下操作:Git global setupgit config --global user.name "wtf"git config --global user.email "[email protected]"git clone ssh://[email protected]:19234/linux/linux_datagrand.gitcd linux_datagrandecho "this is a test file."  >  wtf.txtcat wtf.txtthis is a test file !git add .git commit -m "add a file named wtf.txt"git push -u origin master这样就可以将客户端文件上传到gitlab的仓库里了。
  4. File download
    如果我在gitlab上linux_datagrand.git这个仓库里进行如下操作:添加shiyan.txt和目录test这两个文件,那么我在客户端应该怎么操作才能将新增的文件“拉取”到本地呢?cd linux_datagrandgit pull 或 git pull --rebase origin master说明:建议使用git pull,原因我会在下文说明。cat linux_datagrandwtf.txt  shiyan.txt  test
  5. File submission under Existing files
    如果我在终端上有个目录文件existing_folder,里面的文件需要递交至git库,而你又不想cp到目标库再push,那么你可以这样做:cd existing_foldergit initgit remote add origin ssh://[email protected]:19234/linux/linux_datagrand.gitgit add .git commit -m "Initial commit"在push之前先进性pull操作:git pull --rebase origin master如果不进行pull这一步,会报如下错误:error: failed to push some refs to git。然后:git push -u origin master
  6. Migration or backup of libraries
    # #如我想把linux_ Datagrand.git the files in this library are migrated to Daguan.git as follows: (1) It is necessary to consider the existing branches when migrating, (2) to keep the previous submission records, (3) do not submit the local code directly to the Gitlab so that the previously submitted records and branches are not available.   # #操作如下: Git clone ssh://[email protected]:19234/linux/linux_datagrand.gitcd linux_datagrandlsname.txt shiyan.txt# #查看当前的远程仓库: Git remote-vorigin ssh://[email protected]:19234/linux/linux_datagrand.git (fetch) Origin Ssh://[email protected]:19234/linux/linux_datagrand.git (push) # #添加daguan. Git, a remote repository git remotely add test Ssh://[email protected]:19234/linux/daguan.git Description: Add the remote warehouse format: Git remote add warehouse name [warehouse address]# #查看当前的远程仓库: Git remote- Vorigin ssh://[email protected]:19234/linux/linux_datagrand.git (Fetch) origin ssh://[email protected] : 19234/linux/linux_datagrand.git (push) test ssh://[email protected]:19234/linux/daguan.git (fetch) test ssh:// [Email protected]:19234/linux/daguan.git (push) # #把本地的分支push到远程仓库git Push-u Test Master This time there is an error, the content is as follows: Error: Failed to push some refs to ' Ssh://[email protected]:19234/linux/daguaN.git ' Hint:updates were rejected because the remote contains work which you dohint:not has locally. This was usually caused by another repository pushinghint:to the same ref. Want to first integrate the remote changeshint: (e.g., ' git pull ... ') before pushing Again.hint:See the ' Note AB Out Fast-forwards ' "Git push--help ' for details.# #解决方法: (1) because some branches of Gitlab are protected by default, only users with a master level can commit to the protection branch. and the master branch is the protection branch by default, and other users need to submit by merging issue requests. So we're going to turn this off. Master Branch Protection: Project: "Settings", "Repository", "Protected Branches (Expand)", "unprotect". (2) using the command: Git push-f test master so push the local branch to the Remote repository command: Git push-f test master# #这个时候, we've put Linux_ Datagrand.git the files in this library are migrated to the new library in Daguan.git.
  7. Collection and renaming of libraries
      sometimes after the library migration is complete, the old library is not needed, this time we need to recycle or duplicate the same name, and then the above example illustrates: The requirements are as follows: (1) I have put linux_ Datagrand.git the files in this library are migrated to the new library in Daguan.git, I don't want to use Git clone ssh://[email protected]:19234/linux/daguan.git Set up a local library; (2) I want to change linux_datagrand.git this local library to daguan.git operation as follows: CD linux_datagrand# #先删除原先的origingit remote Remove origin## View current remote repository git remote-vtest ssh://[email protected]:19234/linux/daguan.git (fetch) test ssh://[email protect Ed]:19234/linux/daguan.git (push) # #我们一般都习惯使用origin, so change the name of the test command format: Git remote rename <old> <new>git Remote rename test origin# #再查看当前远程仓库git remote-vorigin ssh://[email protected]:19234/linux/daguan.git (Fetch) Origin Ssh://[email protected]:19234/linux/daguan.git (push)  
  8. Git pull and git pull--rebase
    # #说明:
    Git as a distributed version control system, all modifications are based on the local, in the team collaboration process, assume that you and your partner in the local each have their own new submissions, and your partner before you push the code to the remote branch, so you must first execute GIT pull to obtain the peer's submission, and then to Push your own commits to the remote branch. As with Git's default policy, if the commit line graph between the remote branch and the local branch is forked (that is, not fast-forwarded), Git performs a merge operation, resulting in a meaningless commit record, resulting in confusion over the submitted image.
    # #解决:
    In fact, when pulling operations, using the GIT pull--rebase option is a good way to solve the problem. With the--rebase parameter, Git will rebase the policy instead of the default merge policy if the submission line graph is forked. What are the benefits of using the REBASE strategy? It would be a good idea to borrow the figures from the man Git-merge.
    Let's say that the commit line graph is this way before the pull is executed:

             A---B---C  remotes/origin/master        /   D---E---F---G  master

    If you are executing a git pull, the commit line graph will look like this:

             A---B---C remotes/origin/master        /            D---E---F---G---H master

    The result is an extra H this unnecessary commit record. If you are executing git pull--rebase, the commit line graph will look like this:

                   remotes/origin/master                   |   D---E---A---B---C---F‘---G‘  master

    F G Two commits are re-spliced after C by means of rebase, the excess fork is removed, and the purpose is achieved.
    # #结论:
    Most of the time, git pull--rebase is used to make the submission line graph look better, which facilitates code review.
    However, if you are not very skilled with git, my suggestion is that git pull--rebase practice a few more times, because rebase is considered "dangerous behavior" in Git.
    Also, it should be noted that using Git pull--rebase is more likely to lead to conflicts than direct pull, and if there are more conflicting expectations, it is recommended to pull directly.

Gitlab basic Operations-upload, download, library migration/backup and recycling/renaming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.