Git Rename Files Use git mv command to rename files and directories in current git repository. You can see that the same command is used to move files as well. The difference between both operations is that if you changed the filename only and destination is the same directory then it called rename. Syntax git mv [FILENAME] [NEW FILENAME] Example For example, you have multiple files in your current project. In my case, the files are as followings. rahul@tecadmin:/app$ ls -l total 164 drwxr-xr-x 2 root root 4096 Dec 28…
Read MoreTag: git
Git – Move Files
Git Move Files Use git mv command to move files and directories in current git repository. You can see that the same command is used to rename files as well. Syntax git mv [FILENAME] [LOCATION TO MOVE] Example For example, you have multiple files in your current project. In my case, the files are as followings. rahul@tecadmin:/app$ ls -l total 164 drwxr-xr-x 2 root root 4096 Dec 28 03:29 Documents -rw-r–r– 1 root root 35259 Dec 28 03:28 firstfile.txt -rw-r—– 1 root root 121185 Dec 28 03:59 general.log -rw-r–r– 1…
Read MoreGit – Delete Files
Deleting Files in Git Use git rm command to delete any file from current working directory. You also need to commit and push your changes to delete the file from the local and remote git repository. Syntax: git rm [filename] Example: For example, you have multiple files in your current project. In my case, the files are as followings. rahul@tecadmin:/app$ ls -l total 164 drwxr-xr-x 2 root root 4096 Dec 28 03:29 Documents -rw-r–r– 1 root root 35259 Dec 28 03:28 firstfile.txt -rw-r—– 1 root root 119180 Dec 28 03:28…
Read MoreGit – Stash Changes
Git Stash Changes This option used to stash the changes in the current working directory away. Syntax: git stash [option] Example: Check the current status of files in your project using git status command. Below output showing that one file is modified and 2 files are newly added. rahul@tecadmin:/app$ git status -s M users.txt ?? config.php ?? login.html Run git stash in your project. This will current working directory and index state. You can again run git status and you will find that the modified file is missing from the…
Read MoreGit – Review Changes
Git Review Changes This is a good practice to review all the changes before pushing them to the remote repository. Use git log command to find commit status. $ git log Output:- commit 2693680838b83a37d2e81cd9aae5c54785b6ed52 (HEAD -> master) Author: rahul Date: Fri Sep 1 06:34:06 2017 +0530 Updated Login Page commit 9e42b8c992cf7d7e3662ea486da64950f2f448f3 Author: rahul Date: Fri Sep 1 06:33:18 2017 +0530 “Added Document PDFs” You can find the most recent commit log on top of the output. Now, use commit id to view the more detailed status of specific commit id.…
Read MoreGit – Push Changes
Git Push Changes to Remote Use git push command to copy local changes (Committed changes) to the remote git repository. Syntax: git push [remote_repository] [remote_branch] Git Push Example After committing all the new files or updated files, You can push your changes to remote git repository using “git push” command. The default remote repository referred as origin. You can find this with git remote -v command. The default branch is used master. You can find current active branch with git branch command. git push origin master The above command will…
Read MoreGit – Commit Files
Git Commit Files Use git commit command to commit changes to local git repository. The changes can be any new files added or any existing files content updated etc. Syntax: git commit [-a] [-m “Commit Message”] Git Commit Examples You have a working project on your system and added few new files and modified some existing file. Now you can use git add command to temporarily store the modified files to the staging area called the “index”. Now use below command to commit all files from the staging area to…
Read MoreGit – Add Files
Git Add File to Repository Use git add command to add new files to local git repository. This command will not add ignored files by default, also skipped files silently found in the recursive run. The command will throw an error for the files explicitly specified on the command line. Syntax: git add [FILENAMES] Dry run for Git Add This option doesn’t actually add the file(s). You can use -n or –dry-run to test files if they exist and/or will be ignored with git add command. git add . –dry-run…
Read MoreGit – Clone Repository
Git Clone Remote Repository In this git tutorial, You will learn how to make a clone of remote repository on local system. This will copy all the application files available on remote sever to local system where you can start working. #1. Generate SSH Key Pair To connect git server, you may need to configure key based login. So that it will not prompt for each time you connect to the server. rahul@tecadmin:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/rahul/.ssh/id_rsa): Created directory…
Read MoreGit – Add Remote Repository
Git Add Remote Repository In this chapter of Git Tutorial, You will learn how to add remote git repository in your local project directory. For example you are working on a project for many days, but still not added this project under Git. Now you have create a remote git repository and want to add your project under it. Local Project Dir: /home/rahul/app1 Remote Git URL: [email protected]:projects/app1.git Add Remote Repository Now navigate to your project directory and use git remote add command to connect local directory to the remote repository.…
Read More