1. Project creation and management
Creating the project and managing the project are all part of managing the account. If it is just a cooperative development without management, just browse the second part.
1. Create a project
Log in to the code hosting website and click Add Project, as shown below:
Fill in the corresponding project information, as shown in the picture below:
Completion will generate the url of the project, which will be used after copying the URL. When using the directive, it is necessary to note that each project’s URL is different, as shown in the figure below:
Create the project file locally and create the project description file “readme.md”, as shown in the following figure:
Open git and run the following command to initialize the Git bash client. Go to the project folder and run the following command.
git init
Copy the code
Add the file to the buffer and add comment information
git add README.md
git commit -m "first commit"
Copy the code
Note: On Linux, commit information is in single quotation marks; on Windows, commit information is in double quotation marks. Push the created repository where the URL was previously copied
git remote add origin url
git push -u origin master
Copy the code
After executing the above commands, the project is created successfully, as shown in the figure below:
2. Add collaborators
Click Warehouse Settings to add collaborators and their operation rights, as shown in the picture below:
A simple Git project is created. Collaborators who have access to the project can begin writing the project.
3. Merge request management
When someone initiates a merge request, there will be a corresponding information reminder. You can view the specific request description, as shown in the figure below:
After viewing the details, if it is ok, click the merge request to complete the code merge. As shown in the figure below:
Once the merge is complete, the collaborator simply pulls the code from the main branch to update the change.
2, Git repository use
1. Derive the primary branch
The corresponding project can be used by logging in the collaborator’s account, as shown in the figure below:
Select the project you need and click “enter”, then you can see the cloned URL. In cooperation, it is not recommended to directly clone the project of the main branch, you need to derive your own branch, as shown in the figure below:
After the derivation is complete, you will find that the path of the project is different from that of the main branch. Copy the url of the individual derivation, as shown in the figure below:
2. Configure the remote repository
Open git bash to clone the branch repository using the git Clone URL command, where the URL is the url derived from the individual
git clone url
Copy the code
Add the upstream primary for the remote repository fork, where ruL is the URL for the primary branch
git remote add upstream url
Copy the code
View the Settings address of the warehouse
git remote -v
Copy the code
“If the origin and upstream addresses are displayed, the configuration is successful, as shown in the figure below:
At this point, the warehouse configuration is complete, and development is ready.
2. Update the local repository
Each time you write code, remember to synchronize the remote repository to the local repository to ensure that the code is consistent between the local repository and the remote repository
git pull upstream master
git pull origin master
Copy the code
While upstream updates the main branch to the local repository. Most of the code in the personal branch can only be changed on its own. Generally, the code in the personal branch is the same as the code in the local repository, so the frequency of updating origin is less. It’s basically the main branch because of the number of people working with it, the code changes a lot.
3. Submit the code
Git pull upstream master (git pull upstream master) : use git pull upstream master (git pull upstream master) to synchronize the main branch before committing. Add all updates to the local cache
git add .
Copy the code
View the cache status
git status
Copy the code
Submit to the notes for easy versioning
git commit -m "Submission of Instructions"
Copy the code
Submit to remote personal repository (personal repository name + branch name)
git push origin master
Copy the code
In this way, the code has been committed, and once committed, you need to merge the code from your own branch into the main branch.
4. Code merge
Go to the Remote Management warehouse, go to the personal branch, and click create Merge request, as shown in the picture below:
Select the branch to be merged and the location to pull the code, as shown in the figure below:
After completion, click create merge request and fill in the merge request description has changed the function of the code to facilitate the administrator to manage the code. As shown in the following figure:
At this point the personal development process is complete, and finally the manager only needs to agree to the merge request to see the personal changed code in the main branch.
Git other commands
1. Forcibly pull the override
Forcibly pull personal branch, and overwrite the local repository, mainly used for their own deletion of local files can not be downloaded through the update has been used, of course, you can roll back the previous version.
git fetch --all
git reset --hard origin/master
git pull
Copy the code
2. Local command
git config --listGit add = git add1.# add all files to cache git rm1.Git commit -m"test"Git rm1.-m "test" -m "test" -m "test" -m "testlogGit reset --hard HEAD~n # git reset --hard HEAD~n #Copy the code
3. Upload the local repository to the remote repository
Git pull origin master --rebase git pull origin master --rebase git pull origin master --rebase git push -u origin master -f Origin master # Force upload code to personal branchCopy the code
4. Remote warehouse instruction
Git clone url # git remote add # Git remote add upstream URL # Add a git fetch that will be synchronized to the fork remote Upstream # fetch branches and commit points from upstream repository, "Upstream /master git remote # Git branch # Check all current branches Git branch -d test # select git branch from 'master' where 'master' = 'master' and 'master' = 'master Checkout -b dev # create dev branch, Merge upstream/master: merge the upstream/master branch with the local git master Upstream /dev # merge upstream/dev branch into local devCopy the code