What is Gitlab

  • Version Control System.
  • Providing wiki, issue tracking, CI/CD pipeline features.
  • Open source license.

Why use Gitlab

Installation

  • Gitlab server : https://about.gitlab.com/install/
  • Gitlab client : apt install git || yum install git && git version

Basic Configuration

git config --global user.name "darin"
git config --global user.email [email protected]
git config --list

Creating Repository

mkdir darin-project
cd darin-project
git init . 
or
git init /path-to-dir/directory

git [email protected]:darinvhs/reponame.git
cd reponame
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

Push an Existing Git Repository

cd existing_repo
git remote rename origin old-origin
git remote add origin [email protected]:darinvhs/reponame.git
git push -u origin --all
git push -u origin --tags

About .gitignore

.gitignore is a file that contain list name of files/directories that will be ignored by Git.
Any changes that we make to those file will be not recorded by Git.
How to use .gitignore, just create a file called .gitignore in the project/repository root directory.

cat > .gitignore
/folder1/
/folder2/

Git Modification

There is three condition of files in Git.
1. Modified -> revision (adding/removing files) has been done.
2. Staged -> revision has been marked by git add.
3. Commited -> revision has been saved in version control using git commit.

touch file{1..3.txt}
git add .
git commit -m "adding 3 files to repository"
git push origin master

Git Logging and Different

git log
git log --oneline
git log filename
git log --autoher="darinvhs"

git diff [revision-number]
git diff [filename]
git diff [commit-number] [commit-number]
git diff [branch-name] [branch-name]

Git Revert / Cancel Revision

If modification is not yet staged/commited,
we can cancel the modification using this command :
git checkout filename.

If modification is staged,
we can cancel the modification using this command :
git reset filename *change to modified first
git checkout filename 

If modification is commited,
First you need to know commit number using git log

$ git log filename
commit xxxxxxxxxxxxxxxxxxxxx
commit yyyyyyyyyyyyyyyyyyyyy
commit zzzzzzzzzzzzzzzzzzzzz

After that revert to specific commit using below command :
git checkout zzzzzzzzzzzzzzzzzzzzz filename *will be in staged state.
git reset filename

Other command :
git checkout HEAD~X filename
git revert -n [commit-number]

Git Branch

#list branch
git branch
  darin
* master

#create new branch
git branch developer01
git checkout developer01
git branch
  darin
  master
* developer01

git checkout master
git merge developer01

More details can be found at this link : https://www.petanikode.com/git-branch/

Checkout, Reset, Revert

Git checkout : returns the file in the previous condition, but is temporary.

Git reset : return the file to its previous condition, then delete the next commit history record.

Git revert : restores files by not erasing the commit history.

Working With Remote Repository

git remote
git remote add [remote-name] [url-remote.git]
git remote -v
git remote rename [old] [new]
git remote [remote-name]
git push [remote-name] [branch] #send revision to remote repository

https -> https://github.com/darinvhs/learning.git (password)
ssh -> [email protected]:darinvhs/learning.git (key)