Use GitLab to store code on servers built by the company itself

  • generateSSH key
  • registeredGitLabaccount
  • configurationMac Host
  • GitLabSubmit code
  • useGit-Tower

1. Generate an SSH key

Input at terminal

ls -al ~/.ssh
Copy the code

Check whether the local SSH key exists. Two situations occur. In the first case, the ID_rsa_pub and is_RSA files are displayed on the terminal, indicating that the SSH key already exists. In the second case, if the preceding file is not displayed on the terminal, the SSH Key is not configured on the PC. Enter the following command on the terminal:

Ssh-keygen -t rsa -c "Your registered GitLab email"Copy the code

When the following message is displayed on the terminal:

Generating public/private rsa key pair.
Enter file in which to save the key (/your_home_path/.ssh/id_rsa):
Copy the code

May ask you to enter your boot code. Input again

ls -al ~/.ssh
Copy the code

If id_rsa_pub and ID_RSA are displayed, the file is successfully obtained. Copy pub and paste it into GitLab’s SSH.

pbcopy < ~/.ssh/id_rsa.pub
Copy the code

Title: Paste id_rSA_pub in the Key

2. Register a GitLab account

Generally, the content of the company has been registered for you, assigned to you, or you can provide an email address to add.

Configure the Mac Host

Go to -> Go to folder -> (Enter the folder to go to)

/private/etc/
Copy the code

Find it in the folderHost, copy a copy to the desktop, and configure host.

Note: the left side is the (10.2.5.488) server domain name, and the right side is the domain name you want to replace (a1244.comes.cn). Drag the modified host file into the previous folder and replace the original unconfigured file. You can also use SwitchHost! Tools to configureCopy the code

3.GitLab submits the code

First test whether the connection to the server is successful

SSH -t [email protected] // Company serverCopy the code

or

SSH -t [email protected] // Use the Gitlab serverCopy the code

The connection was successful.

Special reminder: remember to enable the administrator Permission otherwise it will prompt (' Permission denied ') no Permission accessCopy the code

Clone a copy of the warehouse code

Git Clone repository locationCopy the code

Clone is successful. Now try the code to commit the changes

cd /Users/hwxc_ios/hwxc_app/iOS 
Copy the code

CD to the bottom folder (clone from the current folder) or you won’t be able to use git

Git add. Git commit -m "commit" git push -u origin masterCopy the code

4. Git – Tower is used

Since the company built the GitLab warehouse by itself,

Remember to add http:// to Host

If it is a Personal local project, you only need to obtain the Personal Access Token in the following way

Copy the [email protected]:xxxx.git address in gitLab

If you log in with a personal account, log in to Git-Tower in the following interface.

2021-05-24 14:23:49 Update Git-Tower simple to use
1. Create a branch

To create a new branch, drag main to Branches. Merge Branches first CheckOut to the target branch, select the branch to Merge, and click Merge on the Bar to select the branch to Merge

2. Create a remote branch

Create a remote branch in gitLab, obtain the remote branch through the Fetch operation of Origin in Tower, select the remote branch synchronized to, right-click and choose Create branch to create a local branch under the current remote branch.

4. Merge of remote branches

Remote branch merge, usually local branch merge, and commit to a single remote branch, that is, commit to your target branch like main, release, dev, etc

5.stash

The Stash set is only for the current branch. If some functions are not completed but other development needs to be carried out, it can be set to Stash. Can Save Stash

6. Delete the branch

Drag the branch to the branch you want to merge to, right-click Delete

7. Set multiple branches

Dev dev — release line — main trunk


Update: 2021-04-26 22:04:38

My id_RSA and ID_Rsa. pub are expired. So I need to delete the old one and create it again

github Permission denied (publickey)
Copy the code

Typically in Mac SSH keys are stored in

cd ~/.ssh 
rm keyname_rsa 
Copy the code

Create a new Project in gitLab, Project Name is the Name in gitLab, Project sulg is the Name of clone to local, if you need to delete the local folder do the following

CD Current folder sudo rm -r -f Name of the folder you want to deleteCopy the code
git config --global user.name "xxxxxx" git config --global user.email "[email protected]" Create a new repository git clone Git CD 003 touch readme. md git add readme. md git commit -m "add README" git push -u Origin Master Push an Existing Folder // CD existing_folder git init git remote add origin [email protected]:xxxxclone /003.git git add  git commit -m "Initial commit" git push -u origin master Push an existing Git repository cd existing_repo git remote Git git push -u origin --all git push -u  origin --tagsCopy the code

A common mistake is to upload an empty folder

My reason: this folder is a project pulled through Git and has a hidden.git folder, so it is always an empty folder submitted to another remote branch. Solution: delete the.git from the previous code and switch the folder location. The push operation deletes an empty folder left by the remote branch. Delete the empty folder and submit it againCopy the code

Code sample

1. Clone the remote repository to the local repository. Git clone [email protected]: XXX /xxx.git 2 TXT (delete files) git rm -r test (delete folders) // Manually delete local files. 3. Git commit -m "Delete some files." 4 Commit changes to the XXX branch/trunk of the remote repository, depending on the location of the file: git push origin XXX/git push -u origin masterCopy the code

Update the 2021-04-27 11:49:47


Push local code to a remote repository using HTTP

CD Project folder git init git remote add origin http://xxxx.git git add. Git commit -m "Initial" git pull --rebase origin Git push -u origin masterCopy the code

Refer to the link