Below is the example for git workflow and it shows the different stages with git commands to manage local and global repositories (I am us...
Below is the example for git workflow and it shows the different stages with git commands to manage local and global repositories (I am using Git Lab but you can use Github also)
Local Repo:- git
Remote Repo:- Git Lab ( https://gitlab.com)
Consider You are a developer and working on a java project and the name of the project is SpringBootMicroservice. In this project, there are a couple of files ( I am creating some dummy files with extension .java). This project is running on a development box so You need to set up local configuration file ( with your name as Author and your email as email)
Step 1:- Create folder SpringBootMicroservice which has my project files.
mkdir SpringBootMicroservice
Step 2: - Create required files ( restapi.java,dao.java,services.java)
cd SpringBootMicroservices
touch restapi.java dao.java services.java
Step 3: - Initialize this project with git init command
git init
Step 4: - Check that there must be a .git directory get created which is responsible for managing this project's repo.
ls -la
ls .git
Step 5: - Setup the Author name and Author's Email address for this project locally.
git config --local user.name raman
git config --local user.email raman@gmail.com
Step 6:- Verify in .git/config file that the author name and email address is properly configured
cat .git/config
Step 7: - Check the local repository status.(all 3 files should be untracked)
git status
Step 8:- Push dao.java file to the stage area
git add dao.java
git status
Step 9:- Unstaged (moving stage to untracked) dao.java file
git rm --cached dao.java
git status
Step 10:- Push all the files in the stage area.
git add . # or you can use git add -a
git status
Step 11:- Commit dao.java file in the local repo.
git commit -m "dao.java is added" dao.java
git log
Step 12: - Commit all the files in the local repo.
git commit -m " restapi and services java files are added"
git status
git log
git log --oneline
Step 13: - Create a private Repo in Gitlab
Step 14: Add remote repo reference to your local repository.
git remote add origin <<https url of your gitlab repo>>
Step 15: - Check .git/config file you should find a remote login entry.
cat .git/config
Step 16: - Before pushing the local repo's data to remote repo, you should have all the files which are in the remote repo to your local repo. (ReadMe.md file is not in local repo).
git branch --set-upstream-to=origin/main master
Step 17:- Push all the files from the local repo to the remote repo. (By running the below command a master branch will be created in your Gitlab SpringBootMicroservice repo.
git push origin master
Step 18:- To create a new file bal.java in local repo and push it to remote repo.
touch bal.java
git add bal.java
git commit -m "bal.java file is added"
git push origin master
and check on your remote repo bal.java file should exist in master branch.
Step 19:- Create a file in remote repo and pull it in local repo.
Create a file db.java in Gitlab repo
git pull origin master
Step 20:- Modify dao.java file and push it to remote repo.
echo "New lines have been added by master" >> dao.java
git status
git add dao.java
git commit -m "dao.java file is modifed"
git push origin master
COMMENTS