Usage Of GitLab Organizing For Myself

At present, I think cooperation is the hardest thing in the process of developing programs, even if using GitLab.
                                         —— Graycat

Basic Operation

Configure User

1
2
3
4
5
6
$ git config user.name                              # show current user name
$ git config user.email # show current user mail
$ git config --global user.name "<UserName>" # Configure user name
$ git config --global user.email "<UserMmail>" # Configure user mail
$ git config user.name "<UserName>" # Configure user name in current project
$ git config user.email "<UserMmail>" # Configure user mail in current project

Add SSH Keys

Opreate the following command in Git Bash

1
$ ssh-keygen -t  rsa -C  "MailAdress"

You can get a *.pub file in 'C:\Users\UserName\.ssh\', if your os is Windows. And the dir is '/home/user/.ssh/' in Linux.
Copy the content of *.pub file, and paste it to web as a SSH Key.

Add | Rename | Remove ( Remote )

1
2
3
4
5
6
7
8
9
10
11
$ git remote -v                                     # show current remote repository

$ git remote add <RemotetName> <RepositoryURL> # add repository and use a representative name
$ git remote -v # show again
Name-1 http://XXX.96.XXX.132:443/user/project-1.git (fetch)
Name-1 http://XXX.96.XXX.132:443/user/project-1.git (push)
Name-2 http://XXX.96.XXX.132:443/user/project-2.git (fetch)
Name-2 http://XXX.96.XXX.132:443/user/project-2.git (push)
$ git remote show <RemoteName> # show information of remote
$ git remote rename <OldName> <NewName> # change remote respository name if necessary
$ git remote rm <RemoteName> # remove a remote

Add ( Respository )

1
2
3
$ cd /home/user/project-1/src
$ git init # initialize a local respository in '/home/user/project-1/src'
$ git status # show status of file which in Git

Add & Commit & Push

Workspace to stage.

1
2
$ git add <FileName1> <FileName2> ...               # add file to stage
$ git log --graph # show log of commiting

Stage to repository.

1
$ git commit -m "<NecessaryRemarks>"                # commit file to local respository, which have been in stage

Respository to remote.

1
git push <RemoteName> <BranchName>                  # push file from local respository to remote

Push file from respository which on Windows system to one remote first, you'll meet the follow window.

Fetch & Clone & Reset & Checkout

Remote to respository.

1
2
$ git fetch <RomoteName>
$ git clone <Url> <NewFileName>

Respository to stage.

1
$ git reset HEAD <FileName>                         # use file which in resposity replace file which in stage

Stage to workspace.

1
$ git checkout <FileName>                           # use file which in stage replace file which in workspace

Common Situations

Go back to last or other version file which has been commited to respository.

1
2
3
$ git log --graph                                   # show log of commiting
$ git diff [Commit-ID] [Commit-ID] # show difference of two version by commit-id
$ git reset --hard HEAD^ # go back to last version, equals to `git reset --hard HEAD~1`

1
2
$ git reflog                                        # show all the log of commiting
$ git reset --hard <Commit-ID> # go back to any other version by commit-id

Advanced Operation

Create | Switch | Show ( Branch )

Show branch.

1
$ git branch                                        # show all the existing branch

Create and switch.

1
$ git checkout -b <BranchName>                      # create a new branch and switch to it

1
2
$ git branch <BranchName>                           # create a new branch
$ git checkout <BranchName> # switch to a branch

Merge ( Branch )

Merge a source branch called dev into a target branch called master.

1
2
$ git branch <TargetBranch>                         # switch to target branch
$ git merge <SourceBranch> # merge source branch

Common Situation


Unfinished


Actual Combat

Show all the existing branch.

1
2
3
4
5
$ git branch                                         
bug
dev
feature
* master

Show log of commiting.

1
2
3
4
5
6
7
8
9
10
11
12
$ git log --graph                                   
* commit 6bd35e64295557748c43aeb332efec75a65b883d (HEAD -> master, personal/master, group/master, feature, dev, bug)
| Author: duruyao <duruyao@gmail.com>
| Date: Mon Dec 10 12:42:21 2018 +0800
|
| add counter of times to say hello by <duruyao>
|
* commit 2c57f10bdccdd8c06c774c3029d06cbf64823880
Author: duruyao <duruyao@gmail.com>
Date: Mon Dec 10 12:20:33 2018 +0800

a easy program to say hello by <duruyao>

Working in dev branch.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
$ git checkout dev                               
Switched to branch 'dev'

$ git add com/

$ git status
On branch dev
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: com/dry/Main.java

$ git commit -m "add a word to dev branch by <duruyao>"
[dev 8753e08] add a word to dev branch by <duruyao>
1 file changed, 1 insertion(+)

$ git push group dev
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 453 bytes | 151.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote:
remote: To create a merge request for dev, visit:
remote: http://39.96.40.132:443/softengineeringgroup/firstprojectforgroup/merge_requests/new?merge_request%5Bsource_branch%5D=dev
remote:
To http://39.96.40.132:443/softengineeringgroup/firstprojectforgroup.git
* [new branch] dev -> dev

Working in feature branch.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$ git checkout feature                             

$ git add com/

$ git status
On branch feature
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: com/dry/Main.java

$ git commit -m "add another word to feature branch by <duruyao>"
[feature f062b21] add another word to feature branch by <duruyao>
1 file changed, 2 insertions(+)

$ git push group feature
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 467 bytes | 155.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
remote:
remote: To create a merge request for feature, visit:
remote: http://39.96.40.132:443/softengineeringgroup/firstprojectforgroup/merge_requests/new?merge_request%5Bsource_branch%5D=feature
remote:
To http://39.96.40.132:443/softengineeringgroup/firstprojectforgroup.git
* [new branch] feature -> feature

Merge feature branch into dev branch.

1
2
3
4
5
6
7
8
9
10
11
12
$ git checkout dev
Switched to branch 'dev'

$ git merge feature
Auto-merging com/dry/Main.java
CONFLICT (content): Merge conflict in com/dry/Main.java
Automatic merge failed; fix conflicts and then commit the result.

$ git add com/

$ git commit -m "merge feature into dev by <duruyao>"
[dev 0bbadae] merge feature into dev by <duruyao>

Merge dev branch into master branch.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ git checkout master
Switched to branch 'master'

$ git merge dev
Updating 6bd35e6..0bbadae
Fast-forward
com/dry/Main.java | 5 +++++
1 file changed, 5 insertions(+)

$ git push group master
Counting objects: 5, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (5/5), 445 bytes | 148.00 KiB/s, done.
Total 5 (delta 1), reused 0 (delta 0)
To http://39.96.40.132:443/softengineeringgroup/firstprojectforgroup.git
6bd35e6..0bbadae master -> master

Show log of commiting again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$ git log --graph
* commit 0bbadae661a699173a586aadc2b25ee2b66b4e08 (HEAD -> master, group/master, dev)
|\ Merge: 8753e08 f062b21
| | Author: duruyao <duruyao@gmail.com>
| | Date: Tue Dec 11 16:53:39 2018 +0800
| |
| | merge feature into dev by <duruyao>
| |
| * commit f062b219a78d77995c3d1dee3d63a0bbd4e31940 (group/feature, feature)
| | Author: duruyao <duruyao@gmail.com>
| | Date: Tue Dec 11 16:41:25 2018 +0800
| |
| | add another word to feature branch by <duruyao>
| |
* | commit 8753e0843d7bee2615422d5c056713be97cb0ce1 (group/dev)
|/ Author: duruyao <duruyao@gmail.com>
| Date: Tue Dec 11 16:26:03 2018 +0800
|
| add a word to dev branch by <duruyao>
|
* commit 6bd35e64295557748c43aeb332efec75a65b883d (personal/master, bug)
| Author: duruyao <duruyao@gmail.com>
| Date: Mon Dec 10 12:42:21 2018 +0800
|
| add counter of times to say hello by <duruyao>
|
* commit 2c57f10bdccdd8c06c774c3029d06cbf64823880
Author: duruyao <duruyao@gmail.com>
Date: Mon Dec 10 12:20:33 2018 +0800

a easy program to say hello by <duruyao>

View result by web.

Problem & Solution

First

[*] What?
error: failed to push some refs to 'XXXXXXXX'

[*] Why?
It means that your local respository isn't as the same as remote before the pushing.
Reason of the problem may be that you have changed remote by web, but haven't updated local respository, and multiple local respository have push to the same remote is also a possible reason.

[*] How?
If you have commited, using '--rebase' cancel the last commit. And be consistent with remote by using 'pull' is necessary.

1
$ git pull --rebase [RemoteName] [BranchName]

Now, push again. Good Luck.

1
$ git push [RemoteName] [BranchName]

Second


Unfinished