Git Commands Part-1
GIT Commands
git status
git config --list
git config --g
git config --list
git config --g
lobal --list
git config --global --edit
git config --global user.name "<Git_User_name>"
git config --global user.email "<Git_email_address>"
git config user.name
git config user.email
git config --global --edit
git config --global user.name "<Git_User_name>"
git config --global user.email "<Git_email_address>"
git config user.name
git config user.email
git status
git add <file_name>
git commit <file_name>
git commit --amend -m <new_commit_message>"
git push <file_name>
git log
git log -2
git log -p -2
git log <file_name>
git log --stat
git log --stat -2
git log --graph --decorate
git log --author="<email> or <username>"
git rm
git remote add <URL>
git remote -v
git remote show origin
git remote add <alais_name> <SSH_URL> OR <HTTP_URL>
git remote remove origin
git push <remote_URL or Ailas_name> master
git push <remote_URL or Ailas_name> --all
git show <commit_id>
git revert <commit_id>
git clean -f
git clean -n (preview command)
git reset
git revert
git clone
git pull
git fetch
Branch
git branch
git branch -r
git branch -a
git branch -v
git branch <branch_name>
git branch -d <branch_name>
git checkout <branch_name>
git checkout -b <branch_name>
git diff <branch_name>
git merge <branch_name>
git rebase <branch_name>
git push <remote_URL or Ailas_name> : <branch_name>
git brnach -m <old_brnach_name> <new_branch_name>
Tag
git tag
git tag <tag_name>
git tag -d <tag_name>
git push <alias or GIT URL> --tag <tag_name>
git push <alias or GIT URL> --tag
Stash
git stash
git stash list
git stash apply
git stash drop
git stash drop <id>
git stash pop
git stash pop <id>
Cherry-pick
git cherry-pick <commit_id>
Steps to push the deployment files from the local repository to Git repository
1. Create a project directory
$ mkdir project1
$ cd project1
$ cd project1
2. Initialized a local Git empty repository
$ git init
$ git init
$ ls -la
total 36
drwxr-xr-x 1 mferoz 1049089 0 Jan 6 12:29 ./
drwxr-xr-x 1 mferoz 1049089 0 Jan 6 12:28 ../
drwxr-xr-x 1 mferoz 1049089 0 Jan 6 12:29 .git/ ------- git empty initialized repository
3. Create the required deployment files
$ touch Apps_Deployment.java
$ cat Apps_Deployment.java
this file contains the application deployment logic .....
$ touch DB_Deployment.java
$ cat DB_Deployment.java
this file contains the database deployment logic ....
4. Run the git status to check the file status
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
Apps_Deployment.java -------------------------------------------- untracked files (working Area)
DB_Deployment.java
nothing added to commit but untracked files present (use "git add" to track)
5. Push the files from the Working area to Staging Area
$ git add Apps_Deployment.java
warning: LF will be replaced by CRLF in Apps_Deployment.java.
The file will have its original line endings in your working directory
$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: Apps_Deployment.java ------------------ new file moved to the staging area
Untracked files:
(use "git add <file>..." to include in what will be committed)
DB_Deployment.java
6. Push the files from the working area to the local repository
$ git commit -m "Apps deployment code file"
[master (root-commit) 7b42edc] Apps deployment code file
1 file changed, 1 insertion(+)
create mode 100644 Apps_Deployment.java
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
DB_Deployment.java
nothing added to commit but untracked files present (use "git add" to track)
Note: git status won't list the files which are moved to the local repository
7. Move the remote files to GIT repository
Create the repository in the Github
Step-1: Login to https://github.com/
Step-2: On the right side top corner click on "+" symbol and click on "New Repository" option and pass the repository name based on your project requirement and click create a repository.
Step-3: Configure the remote repository
$git remote add origin p1 https://github.com/feroz7861/Project1.git
$ git remote add p1 https://github.com/feroz7861/Project1.git
Note: Here p1 is the alias name, instead remembering the complete URL always we could use p1.
$ git remote -v
origin https://github.com/feroz7861/Project1.git (fetch)
origin https://github.com/feroz7861/Project1.git (push)
p1 https://github.com/feroz7861/Project1.git (fetch)
p1 https://github.com/feroz7861/Project1.git (push)
$ git remote show origin
* remote origin
Fetch URL: https://github.com/feroz7861/Project1.git
Push URL: https://github.com/feroz7861/Project1.git
HEAD branch: (unknown)
Step-4: Push the code to GIT repository
$ git push p1 master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 285 bytes | 285.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/feroz7861/Project1.git
* [new branch] master -> master
Note: It will prompt the password to push the code.
Git repository image: file named -> Apps_Deployment.java
Check the log or commit details
$ git log
commit da24b8ab9a0ca655f4d352c87ff04cebbb3c9581 (HEAD -> master, p1/master)
Author: feroz7861 <feroz.moh09@gmail.com>
Date: Wed Jan 6 14:35:47 2021 +0530
DB deployment code
commit 7b42edccd422cc57b0fc395a06a5f7b2e3cb02d4
Author: feroz7861 <feroz.moh09@gmail.com>
Date: Wed Jan 6 12:44:01 2021 +0530
Apps deployment code file
$ git log -1
commit da24b8ab9a0ca655f4d352c87ff04cebbb3c9581 (HEAD -> master, p1/master)
Author: feroz7861 <feroz.moh09@gmail.com>
Date: Wed Jan 6 14:35:47 2021 +0530
DB deployment code
check the commit files and the details
$ git show 7b42edccd422cc57b0
commit 7b42edccd422cc57b0fc395a06a5f7b2e3cb02d4
Author: feroz7861 <feroz.moh09@gmail.com>
Date: Wed Jan 6 12:44:01 2021 +0530
Apps deployment code file
diff --git a/Apps_Deployment.java b/Apps_Deployment.java
new file mode 100644
index 0000000..8610497
--- /dev/null
+++ b/Apps_Deployment.java
@@ -0,0 +1 @@
+this file contains the application deployment logic .....
$ git log DB_Deployment.java
commit da24b8ab9a0ca655f4d352c87ff04cebbb3c9581 (HEAD -> master, p1/master)
Author: feroz7861 <feroz.moh09@gmail.com>
Date: Wed Jan 6 14:35:47 2021 +0530
DB deployment code
How to print only print the file name?
$ git show --pretty="" --name-only 7b42edccd422cc57b0
Apps_Deployment.java
How to know which files are recently committed and how to clean up the problematic or bad files?
list the recent files or the recent commit IDs
$ git log
commit 2dcfdab0b1fe2a52de0d2e22611fe6bc0877db84 (HEAD -> master, p1/master)
Author: feroz7861 <feroz.moh09@gmail.com>
Date: Wed Jan 6 16:04:16 2021 +0530
bad code logic check
commit da24b8ab9a0ca655f4d352c87ff04cebbb3c9581
Author: feroz7861 <feroz.moh09@gmail.com>
Date: Wed Jan 6 14:35:47 2021 +0530
DB deployment code
commit 7b42edccd422cc57b0fc395a06a5f7b2e3cb02d4
Author: feroz7861 <feroz.moh09@gmail.com>
Date: Wed Jan 6 12:44:01 2021 +0530
Apps deployment code file
pick the recent commit ID "7b42edccd422cc57b0fc395a06a5f7b2e3cb02d4"
$ git revert 7b42edccd422cc57b0
Removing Apps_Deployment.java
[master 2817128] Reverted "Apps deployment code file"
1 file changed, 1 deletion(-)
delete mode 100644 Apps_Deployment.java
$ ls -lrt
total 1
-rw-r--r-- 1 mferoz 1049089 54 Jan 6 12:34 DB_Deployment.java
-rw-r--r-- 1 mferoz 1049089 0 Jan 6 16:01 bad_f
Note: It removes the file if newly created or code from the files if they are newly added to the file from the local repository but not from the GIT repository
to remove from GIT repository run the push command again
$ git push p1 master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 280 bytes | 280.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/feroz7861/Project1.git
2dcfdab..2817128 master -> master
Post the Push the files or any newly modified lines would be deleted from GIT repository
How to clean up the unwanted files
$ git clean -f
Before cleaning files make sure to review/preview the clean files and then clean those files.
$ git clean -n
Would remove file1.java
Would remove file2.c
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
file1.java
file2.c
nothing added to commit but untracked files present (use "git add" to track)
$ git clean -f
Removing file1.java
Removing file2.c
$ git status
On branch master
nothing to commit, working tree clean
Https Codes
100
200
300
400
500
GIT ignore file
.gitignore
.gitignore
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
.classpath
.projects
$ cat .gitignore
.classpath
.projects
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)


Comments
Post a Comment