Basic Git Commands with Example || Upload Folder / Project To Gitlab

Basic Git Commands with Example

git config

usage: git config  

You can use it to configure the author's name, email address, file formats and many more to be used with your commits.

git init

Usage: git config –global user.name “[name]”  
Usage: git config –global user.email “[email address]”  
This command sets the author name and email address respectively to be used with your commits.

git add

Usage: git add [file]  
This command adds a file to the staging area.
  • git add -A stages all changes
  • git add . stages new files and modifications, without deletions
  • git add -u stages modifications and deletions, without new files


git checkout

Usage: git checkout [branch name]  
This command is used to switch from one branch to another.
Usage: git checkout -b [branch name]  
This command creates a new branch and also switches to it.

git commit

Usage: git commit -m “[ Type in the commit message]”  
This command records or snapshots the file permanently in the version history.

git status

Usage: git status  
This command lists all the files that have to be committed.

git pull

Usage: git pull [Repository Link]  
This command fetches and merges changes on the remote server to your working directory.

git push

Usage: git push [variable name] master  
This command sends the committed changes of master branch to your remote repository.
Usage: git push [variable name] [branch]  
This command sends the branch commits to your remote repository.
Usage: git push –all [variable name]  
This command pushes all branches to your remote repository.
Usage: git push [variable name] :[branch name]  
This command deletes a branch on your remote repository.
git merge

Usage: git merge [branch name]  
This command merges the specified branch’s history into the current branch.

git clone

Usage: git clone [url]  
This command is used to obtain a repository from an existing URL.

git branch

Usage: git branch  
This command lists all the local branches in the current repository.
Usage: git branch [branch name]  
This command creates a new branch.
Usage: git branch -d [branch name]  
This command deletes the feature branch.

git show

Usage: git show [commit]  
This command shows the metadata and content changes of the specified commit.

git reset

Usage: git reset [file]  
This command unstages the file, but it preserves the file contents.
Usage: git reset [commit]  
This command undoes all the commits after the specified commit and preserves the changes locally.
Usage: git reset –hard [commit]  
This command discards all history and goes back to the specified commit.

git tag

Usage: git tag [commitID]  
This command is used to give tags to the specified commit.

git remote

Usage: git remote add [variable name] [Remote Server Link]  
This command is used to connect your local repository to the remote server.

Upload Folder / Project To Gitlab

GitLab is a web-based DevOps lifecycle tool that provides a Git-repository manager providing wiki, issue-tracking and continuous integration/continuous deployment pipeline features, using an open-source license, developed by GitLab Inc

You can also upload existing files from your computer using the instructions below.
Git global setup
git config --global user.name "USERNAME"
git config --global user.email "USEREMAIL"
Push an existing folder
cd existing_folder
git init
git remote add origin https://gitlab.com/XXXXXXXX/XXX.git
git add .
git commit -m "Initial commit"
git push -u origin master
Create a new repository
git clone https://gitlab.com/XXXXXXXX/XXX.git
cd projectname
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 https://gitlab.com/XXXXXXXX/XXX.git
git push -u origin --all
git push -u origin --tags

Cloning a repository

  1. On GitHub.com, navigate to the main page of the repository.

  2. Above the list of files, click  Code."Code" button

  3. To clone the repository using HTTPS, under "Clone with HTTPS", click . To clone the repository using an SSH key, including a certificate issued by your organization's SSH certificate authority, click Use SSH, then click . To clone a repository using GitHub CLI, click Use GitHub CLI, then click .The clipboard icon for copying the URL to clone a repository

    The clipboard icon for copying the URL to clone a repository with GitHub CLI

  4. Open Terminal.

  5. Change the current working directory to the location where you want the cloned directory.

  6. Type git clone, and then paste the URL you copied earlier.

    $ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
  7. Press Enter to create your local clone.

    $ git clone https://github.com/YOUR-USERNAME/YOUR-REPOSITORY
    > Cloning into `Spoon-Knife`...
    > remote: Counting objects: 10, done.
    > remote: Compressing objects: 100% (8/8), done.
    > remove: Total 10 (delta 1), reused 10 (delta 1)
    > Unpacking objects: 100% (10/10), done.

GitLab flow




Example Basic steps 
1.git init
2.git checkout branchname
3.git add -A
4.git commit -m "note"
5.git pull origin master
6.git push origin branchname
7.git checkout master 
8.git merge branchname
9.git push origin master
10.git checkout branchname