Upload local projects to Gitlab or Github using git commands


1. First, you need to install git locally. You can use the built-in command tool for Mac.

2. Create a project on gitlab, as shown in the figure below, click the plus sign in the upper right corner to go to the project creation page, fill in the project name, and select the project access permission. Private members can only access it if they are authorized.

gitlab.png

3. Open the folder where the project source code is located, and delete the IDE configuration information of the project (this is to ensure that the IDE configuration information will not be uploaded to Gitlab, or you can use the command line to filter the configuration file when uploading, personally I think it is more convenient to delete it visually )
.Important: git clone the code repository address of the remote gitlab to the local. Drag the project into the git clone folder.
Reconfigure the user.name and user.email, and that's it.
git config --global user.name "xxx"
git config --global user.email "xxx"

If some files exceed 200M, you can add to ignore file
vim .gitignore

add the file in

Can be used to check the status of the repository:
git status

git remote add origin <your project address> //Connect the local project with the code cloud project

4. Open the git command window:
git clone address of remote code repository
cd (folder path of git clone)

git pull origin master//Update must do

// git remote add origin The project you just created is connected to
git add .
git commit -m 'comment'
git push -u origin master Push the code to the gitlab side

5. Create and switch the local branch of the branch and push it to the remote server;

git branch : Check how many branches there are in our git repository, and which branch we are currently working on. The one with an * in front of it is the branch we are currently in.

git branch -a : View remote branches.

git branch name : Create a branch, and the pointer of this branch points to the latest commit object, which is the same object as HEAD. For example, git branch test means to create a local test branch.
git checkout name : switch to the target branch, our default master branch is master.
git checkout –b name: Create and switch branches.
git push origin name: Push the local name branch to the remote server.

git status : View file change status. Before or after adding files, we will use git status to see the changed files (usually changed files will be displayed in red).

//Set to show hidden folders
defaults write com.apple.finder AppleShowAllFiles YES

6,遇到的问题,即解决办法:
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to '[email protected]:******/Demo.git'
hint: Updates were rejected because the tip of your current branch is behind

1.使用强制push的方法:

$ git push -u origin master -f

这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。

2.push前先将远程repository修改pull下来

$ git pull origin master

$ git push -u origin master

3.若不想merge远程和本地修改,可以先创建新的分支:

$ git branch [name]

然后push
$ git push -u origin [name]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325564373&siteId=291194637