DEV Community

PRIYA K
PRIYA K

Posted on

GIT COMMANDS

*INSTALLATION *
step 1:Register -> sign in ->sign up in GITLAB
step 2: Install VisualStudio
step 3:

In Command Prompt
Copy - ctrl + shift + C
Paste - ctrl + shift + V

Command Prompt

1. check the Git Version
   git --version
2. Install Git by command
   sudo apt install git
   password: Welcome@123
   y / n
   y
3. Updating latest Version
   sudo apt update
4. Updating System
   sudo apt upgrade
Enter fullscreen mode Exit fullscreen mode

step 4:
In GITLAB
Group -> New group -> Create Group -> Group Name -> Visibility level -> Public -> Who will be using this group? Just me -> Create Group

step 5: Click Project -> Create Blank Project -> give project name -> Change Visibility Level -> Create Project

GIT CLONE
Step 1: In GITLAB
Select Group -> Project -> Click that particular Project -> Code -> Clone with HTTPS -> Copy URL

Step 2: Select Location in Computer Folder
File Manager -> Documents -> right click -> create New Folder -> Select that particular folder ,right click -> Open In Terminal

step 3:
In Command Prompt:

git clone (Paste the copied URL)
Enter fullscreen mode Exit fullscreen mode

Working Directory to Remote Repository
step 1: select the particular folder location in computer
open in terminal(creating txt file in computer folder)

git status
touch file1.txt
git status
Enter fullscreen mode Exit fullscreen mode

step 2: change untracked file into tracked file(working file to staging area)
open in terminal

git add file1.txt
git status
Enter fullscreen mode Exit fullscreen mode

If you want to untracked the file

git restore --staged file1.txt
git status
Enter fullscreen mode Exit fullscreen mode

Add all files

git add .
git status
Enter fullscreen mode Exit fullscreen mode

step 3: change staging area files to local repository

git commit -m "learn git"
git config --global user.name"priya K"
git config --global user.email priya.k.2021.ad@ritchennai.edu.in
git config --list
Enter fullscreen mode Exit fullscreen mode

step 4: local repository file to remote repository

git status
git log (see commit message)
git push 
username:
password:
Enter fullscreen mode Exit fullscreen mode

check the file in remote repository

Edit the file in Remote Repository (write in gitlab file) and working directory
step 1: Edit the file in Remote Repository
gitlab-> project ->click file1.txt file(empty file) -> edit -> open in web IDE(type a mesage in txt file) -> save the file as ctrl + s
-> branch symbol in left corner(click that symbol)->give commit message -> commit to main -> continue
step 2:Edit the file in working directory
select the folder in computer location
give right click -> open in terminal
open in terminal

git status(nothing to commit)
git pull
Enter fullscreen mode Exit fullscreen mode

open the file in working directory

delete the file
in computer folder -> select the file and delete it.
open in terminal

git clear
git status
git add file1.txt
git status
git clear
git commit -m "deleted"
git push
username
password
Enter fullscreen mode Exit fullscreen mode

deleted that file in gitlab

create a file in computer folder

touch file2.txt(create a file in computer folder)
git status
git add .
git commit -m "second"
git push
username:
password:
Enter fullscreen mode Exit fullscreen mode

rename a file
in computer folder -> right click -> rename ->git status

git add file1.txt
git commit -m"one file"
git push
username:
password:
Enter fullscreen mode Exit fullscreen mode
git add .
git commit -m"second file"
git push
username :
password :

Enter fullscreen mode Exit fullscreen mode

deleted file2.txt

git log
q(to come out)
Enter fullscreen mode Exit fullscreen mode
git log --oneline
Enter fullscreen mode Exit fullscreen mode

git diff
select the folder in computer location -> open with notepad ->type a message and save it (ctrl + S)

in terminal

git diff
Enter fullscreen mode Exit fullscreen mode
git status(nothing to commit)
git branch
Enter fullscreen mode Exit fullscreen mode
**create a branch**

Enter fullscreen mode Exit fullscreen mode

syntax : git branch branch_name

git branch test
git branch
ls(list of file)(linux command)
Enter fullscreen mode Exit fullscreen mode

go from one branch to another branch
syntax: git checkout branchname

git checkout test(switched to test)
git branch
ls
Enter fullscreen mode Exit fullscreen mode

Rename the branch name
syntax : git branch -m oldname newname

git branch -m test testing
git branch
Enter fullscreen mode Exit fullscreen mode

delete the branch
syntax: git branch --delete branchname

git branch --delete testing
git branch
git checkout main
git branch
git branch --delete test
git branch
Enter fullscreen mode Exit fullscreen mode

deleted branch test

git conflict
after pushing the file
in gitlab -> edit -> open in webid -> type a message and save it(ctrl + s) -> branch symbol at left corner -> commit to main

refresh the file in gitlab

type another message in webid
click that file in computer location and right click and open in terminal

git status(modified)
git pull
username:
password:
(overwritten error)
git stash
git pull
username:
password:
Enter fullscreen mode Exit fullscreen mode

open in both open in webid and gitlab

take back from stash

git stash pop
Enter fullscreen mode Exit fullscreen mode

change the message in webid and save it(ctrl + s)
open in terminal

git status(modified)
git add .
git commit -m"learn commit"
git push
username:
password:

conform by opening in gitlab
Enter fullscreen mode Exit fullscreen mode

git merge

git branch
git branch develop(create a branch)
git branch
git checkout develop(move to develop branch)
git branch
Enter fullscreen mode Exit fullscreen mode

type a message in webid and save it
open in terminal

git status(modified)
git add file1
git status
git commit -m"commited from dev branch"
git checkout main
git status
git branch
Enter fullscreen mode Exit fullscreen mode

reflect the changes from develop branch to main branch
open in terminal

git merge develop
git push
username:
password:

Enter fullscreen mode Exit fullscreen mode

open that file in gitlab main branch

Top comments (0)