Common commands for git submission projects and the usage of git branches

1. The first step is to clone the project from the git hosting platform. I will use the idea as an example here:

 

Fill in the git url and store the local directory name and project name
 

 

 
2. If you have made some changes to the project, you can execute the git command and submit it.
There are two ways:
1. Use the graphical interface that comes with idea to operate. Select the modified file, right-click and select git--add to add to the local repository.
 

 

 
 
Then select git --commit file to submit
 

 

Then commit and push, submit to the remote warehouse
 

 

 
2. Use the command line method, personally prefer this method.
First open terminal
 

 

The execution steps are the same:
1.git status //View changed files
2. git add filename
3.git commit -m 'commit comments'
If you feel wrong here or don't want to submit, use the following command to cancel the add operation before the specified file
git reset HEAD filename
 
git reset HEAD . Cancel the previous add operation of all previous files
4. git push //Submit to the remote warehouse
 
 
 
Branch:
In the company, you are usually not allowed to submit directly to master, but to submit a branch, wait for the project manager or product manager to review and then merge (merge)
 
1. First, you can create a development branch locally by yourself
    git branch dev to create a branch
    git branch View local branch
    Delete local branch: git branch -d dev
    Force delete: git branch -D dev
 

 

 
 
2. Switch branches
git checkout dev
 

 

3. View remote branches
git branch -r
 

 

4. Do git add file
5.git commit -m "***"
6.git push origin dev:dev //Create remote branch dev and submit
 

 

 git push origin :dev //delete remote branch
 
 
Then go to gitlab to create a new merge request:
 

 

 
Choose your own local branch and target branch:
 

 

 
It is ok to submit a merge request. If you click accept merge request, it will be merged to master, but this is usually not your operation, but after waiting for the boss to review, he will merge:
 

 

 
Other commands Common commands:
 
Pull the remote repository to the specified local branch: $ git pull [remoteName] [localBranchName]
 
Push remote repository: $ git push [remoteName] [localBranchName]
 
Create a new branch and switch to the new branch immediately: $ git checkout -b [name]
 
Create a remote branch (local branch push to remote): $ git push origin [name], the default remote will automatically create a name branch. This command was originally: git push origin [local] : The abbreviation of [remote]
 
Delete remote branch: $ git push origin :dev

Guess you like

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