once you have git repository ready as explained in previous tutorial. its tim to work with file. currently the git folder is empty.
the process:
- create a file and save in git project folder
- add file to staging env ( new file –> staging env –> git repo)
- commit file into git repository from staging env
- create branch to manipulate on file for example bug fixes, patch release or development.
- merge the branch code to master branch
1. Create File
lets create one file using code editor.
I prefer visual code editor and create demo.java as below
1 2 3 4 5 6 |
class Demo { public static void main(String[] args) { System.out.println("hello world"); } } |
Please make sure to save this file inside same folder where we initialize git.
once done, check with below command if file is listed in project folder.
1 |
ls -lrt |
check the git status by:
1 |
git status |
you will see following output:
1 2 3 4 5 6 7 8 9 10 11 |
MacBook-Air git % git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) demo.java nothing added to commit but untracked files present (use "git add" to track) MacBook-Air git % |
Now the git understand there is one new file which is in untrack status means not been added to staging yet
2. Add New File to staging:
before moving to git repo, we need to move first the file to staging env and then to git repo
use command to move to staging:
1 |
git add . |
it will add all untracked file to staging environment and make ready for commit.
3. Commit The File:
syntax:
1 |
git commit -m "message" |
once executed command, it will look like this:
1 2 3 4 |
MacBook-Air git % git commit -m "initial commit" [master (root-commit) f631949] initial commit 1 file changed, 6 insertions(+) create mode 100644 demo.java |
check with GIT log command as shown below:
1 2 3 4 5 6 |
MacBook-Air git % git log commit f631949b082b0a835949e7d922318a23aa104023 (HEAD -> master) Author: shrikant <worldoffullstack@gmail.com> Date: Sun Feb 5 21:29:17 2023 +0530 initial commit |