Version Control System: Source code is stored centrally and maintain its version when any changes made. There are two types:
Centralized:
Central Repository: All source code is centrally managed in one place, user required internet to access the file and make changes and save it.
Central Versioning System/Old Version Control System: when a programmer writes a code or develop a program then it is save locally or in network storage or in cloud. if this file need to amend then again it saved with new name to keep both files, in this scenario only one user can execute the file, if multiple user needs to write on the same file and they all save it with new names then it will be lot of files and make confusion that which programmer has made what changes. The solution came up that keep main file in the central location and all users who are working on that file download in their system and make changes and keep a copy in their local system, once they complete their task on the file then upload in the central location with unique name using their ID and time and date so it can be identified in the central location. If they do not change name then this file will overwite in the central location.
There will be lot of manual work in the central system to check and remove overwrite, duplication and merge some files. Some one has to manage that which programmer send file first and need to check code is correct then second programmer can use this file and make copies properly and in a sequence manner. In this type of work they required a team to manage files in the central system. Version control system has been introduced. This central location become the server and any user uploading file then its version is maintained automatically in the central system. This version control system also installed on client computer so the client do not need to save file every time when they make changes as it will be done automatically, once they finished the work then final copy will be uploaded in the central system.
Distributed:
Distributed Repository: Source code will be pulled in user's computer and users will work locally. Once the code is successfully completed than push/commit to central location. In this user will have a copy of source code as well.
Code
Code
Git
Introduction
Git is a (DVCS) distributed version control system or source code management (SCM) system. To make version control system install git on central and client location.
In 1991 when linus Tovalds introduced linux kernel was using verion control system of BIT, later it was stopped due to some reason and then Linus introduced GIT open sourced which was command line.
Git Repository:
Local : install git in local computer.
Remote:Git-hub is a central repository or storage. The organization took open sourced GIT from Linus Tovalds and done extra coding and made it graphical and web based. It is advanced version of GIT. It is ready to use software like software as a service (office365) and anyone can pay and use it online. Bit bucket and SBN is also available in the market. Git-Hub is centralised distributed system. Go to Git-hub create account, create public or private repository.
private version: chargeable
public version: free.
Git Access: Git can be access with command line or gui.
Git Bash: it is a terminal provided by git to run commands on git.
Git CMD: Git Command is a terminal to run git commands.
Git GUI: Gui based Git Terminal.
Git profile: Create profile to track the users works and commit changes, create profile with name and email.
Git Installation on Windows Machines for local repository:
Download git software from git site, click here to dowload windows git or from Powershell install Chocolatey:
Install with default options.
git can be run from Git CMD, Git Bash, Git GUI
Git Installation on Linux Machine for local repository:
Repository: Folders on which versioning is enabled, folder is converted to working directory by using #git init command.
Local Repository: It is a folder in a clients local system where they save all work files, once they finish coding move/change to staging area and then commit to local repository. each time they commit it generates commit ID along with user details.
Git Installation on Clients: Developers files are maintained in local system. there are 3 types of files (Untracked, Staging and local repository)Install git package. Requied to install git package in the machine.
#yum install update
#yum install git -y
#git init (it enable versioning and convert directory into working tree/directory), a hidden .git folder is created check #ls -a
Git Code File creation:
#touch filename
#git add filename: it will move files from untracked to staging area.
#git status: it shows the status of files in the repository.
#git commit -m "statement": It moves files from staging to local repository.
#git log: it shows how many commits has been done
#git log --oneline (number of commits shows in less details)
File edit / amendment: when developer edit the committed file it will be untracked modified file, it should move to staging area
#git add .
#git commit --amend -m "description"
Git reset:
#git reset file name (it will move file from staging area to untracked area)
Removing a Commit: When developer write codes and achieve task then commit, like that he made several commits which some are unnecessary and want to delete.
first commit cannot be removed. it will not delete the commit instead is squashed.
#git rebase -i HEAD~4 (dependes 4, 5 ..n commits)
remove word pick and insert squash for the commit need to be removed. save it.
choose a selective commits/cherry pick:
#git cherry pick commit ids (you should be in master branch)
choosed commits will be in the top.
Git Central Repository Workflow:
Central Repository: It is a folder maintained centrally where clients upload their files and new version is applied.
Push: Clients commit the files in local repository which move to central repository, Once code is compiled then push(upload) into the central repository.
Pull: Clients pull (download) files from central repository into local repository.
Git Server installation on prem local network: All source code files are maintained in central system, Git server is installed in local network else Git _hub is used for central repository through internet.
#yum install update
#yum install git* -y
#git init --bare
Git Installation on Client/Server Architecutre on-premises:
Create three VMware Centos machines, setup IP address, ping each other (enter IP addresses in /etc/hosts file) and have internet access.
#yum install update
#yum install git (install package on all machines, it will install the package from internet, if you do not have internet then keep package in local repository first then run, git package is available in centos o/s rpm CD by default. In google search git rpm download and keep in local repository. To setup internet on your vmware machine # nmcli connection add con-name dhcp ifname ens33 type ethernet autoconnect yes #nmcli connection up dhcp
Git Server:
#mkdir /project
#cd /project
#git initi --bare (on server it creates central repository),
Git client1:
#mkdir /dev1
#cd /dev1
#git init(on client1creates local repository)
# vim code1 :Developer1 write a code (Welcome to Devops Training) save it.
#git add code1 (move to staging area)
#git commit -m “First Code file from developer1 on 16 01 2021 at 19:00) code1 ( it will ask who you are, need to provide email address and name then run file again),
#git config --global user.name “developer1” then run commit command again.
#git remote add origin root@192.168.61.131:/project :Now create a link with central repository in developer1 machine before push (upload) file on central repository.
#git push origin master (it makes ssh connection, asked to provide password of gitserver, in industry we do not provide gitserver password to client, so we run #ssh-keygen command on client machine which creates private and public key id_rsa and id_rsa.pub in user home folder(/root/.ssh/id_rsa & /root/,ssh/id_rsa.pub). copy the id_rsa.pub and sent it to server administrator #.
Git server administrator will create a hidden folder in his home folder .ssh and create a file #vim authorized_keys and paste the key.
Now push the file again #git push origin master
#git log or #git show :Go to git server /project and run (file is uploaded)
Now user edit code file or add some codes:
#vim code1 “This is the second line added”
#git status (modified file) in untraced area.
#git add . (move to staging)
#git commit -m “new code added at 2040 by developer1” code1
#git push origin master
#git show (new line added)
Git Client2:
#mkdir /dev2
#cd dev2
#git init (on client2 creates local repository).
#git add code2
Developer2 has joined the project and he will download or pull files to start working on the project.
#git clone root@192.168.61.131:/project :Go to developer2 machine and run (to get the file from central repository, it will ask for password, run the ssh-keygen and provide key to git server administrator) run again clone command.
File has been pulled into the home folder>project, check file code1.
Code
Code
Code
Commands
Git Log
git help log
To check how many commits is done from developers. Can run on server or clients
#git log --before “2021-01-18” (it shows commit records before 18 jan, you can use --after or both)
#git log --grep “updated by developer1” (can check with commit message)
#git log -G“Welcome” (it will show the commit in which welcome used in code)
#git log -p (it shows in every commit what changes has been done).
#git log --stat (it shows which line inserted and which is removed in code file)
#git log --oneline (it shows commit id and comment in one line)
#git log --graph (it shows in graph which line added and removed)
Branch
Git Branching in Local Repository:
Git Branching in Central Repository:
c:\git branch -a : it will show all branches local and remote.
c:\git fetch -p
Renaming Local and Remote Branch:
c:\git branch -m <old_name> <new_name> (if you are on different branch)
c:\git branch -m <new_name> (if you are on same branch)
c:\git push origin --delete <name>
Push the new branch to remote:
c:\git push orign <branch_name>
Branches are created to keep course code of different functionality in separate repostories. some developers are creating codes for linux application and push files on branch1 and some creating codes for windows application and push files on branch2, it will forward to Jenkins for compiling. Working tree by default is in master branch.
Creating Branch:
#git branch branchname
#git workbench branchname (move to branch)
#git branch (display branches and pointer to branch)
When a client write a code, commit from local repository, a default master branch is created in the central repository and once they perform push it comes into master (git push origin master).
A jenkins server is intergrated with this master branch and a job is executed on the Jenkins sever that whenever an entry is made in the master origin then it should forward to build server.
Everytime a user commit then this process goes on until software is build and completed.
In jenkis second job is created and defined that once job1 is completed then start job2 and in build server a software is ready should forward it to Deployment server (Ansible).
A third job is created in jenkins that a playbook is created and it should deployed ready software to green and blue deployment on production servers.
In green and blue deployment you have number of servers in each and it is used as active and passive servers,
Load balancer on each green and blue deployment is configured,
CNAME record is created in DNS to forward the traffic on load balancer received from customer through internet.
If there is a bug in the completed software detected after deployment on production then the above cycle run where developer amend the code and commit which comes to master branch then Jenkins then ansible and then production.
If the bugs still continues then repeat the process which results in production engineer suggest only to deploy the bug free software on production.
To resolve this developer create a branch and push the file on branch instead of master.
We integrate staging branch with Jenkins.
Another build server is created and job1 send to new build server.
A second Ansible server is configured and job2 is created which define to create transferred complete software to ansible. A playbook should be created.
A third job is created and we have created pre production server in which multiple servers are configured. In third job software deployed to pre production.
Quality test engineer work at pre production for testing the software.
Master branch is linked with production and staging branch is linked with pre production where quality testing is perform.
Once the quality team confirm bug free software then we merge all commits from staging branch with master branch.
Either git engineer or developer perform the merge task.
Create a folder mkdir /xyx
#git clone
#git fetch
#git merge staging
#git push origin master
Now the process linked with production will run.
If developers are creating a new verion of that softwre then a new branch will be created and keep their code separately.
Configuration of Staging Branch:
#git branch (list branch exist)
#git branch staging (creates branch), on first branch creation all contents from master copied into staging branch, after this content will not copied either you commit in master or branch.
#git log staging (cotents of master copied)
#git fetch (run on client computers, it will fetch branch)
#git branch -a (run on client computer to view branches)
Now file is updated in staging not in master, once all coding is done administrator will merge both branches and file get updated on master branch.
Merge Branch commits:
It merge all commits from branch to master in linear format.
To perform merge you should be in parent branch. To perform rebase you should be in child branch.
#git merge staging master (it merge staging and master branches)
Merge Conflict Error:
Once central and local repositories are created, any one developer will create a file and start wirting code on it and this developer will add and commit the file. This developer will make a link with server and push the file. The remaining developers will clone the central repository folder in their local repository and start working on it. All developers are working on the same file, they have been told to pull updated file first and then write their code and commit and push on git server. When they commit a new version number will be assign to file and then it will be uploaded on server.
Every developer has to work in a sequence manner to maintin correct versioning and avoid conflict.
Suppose a developer did not pull latest file and start working on existing file from local repository. When this developer tries to commit and push then server will reject as this developer did not pull the latest file.
Now the developer has to pull the latest file and it will merge with the code he made it without pulling the updated file.
Some time automatically merge get failed, because the portion of update file is missing in the developer file and he wrote his code on that area. It will get merge conflict.
Developer will check updated file and local repository file and keep changes accordingly with mutual decision.
Delete Branch:
git branch –D branch-name (delete from local) git push origin :branch-name (delete from remote)
git remote prune origin (remote branch deleted but still it shows in local repository)
.gitignore
It ignores the files and do not include in commit. Developers creates code files in java and compile it, it generates some additional class files which you do not want to commit.
#git add .
#git commit -m "message"
Stash: Store in safe hidden place, it is used for leaving unfinished work where git cannot be accessed.
Rebase:
Rebase + Merge: It is a fastforward merge. in rebase commits from the branch will be added to the top of the master branch not in linear way.
To perform rebase you should be in child branch and rebate to master branch.
#git rebase master (now merge) rebase is used to point where merge should be done on top or linear way.(now go to master branch and run)
#git merge star1
#git log --oneline
you will get result of commit m1,m2,m3,s1 (if you perform rebase on king1 branch and merge you will get result m1,m2,m3, s1, k1)
Re-Arrange Commit History using Rebase: Developer receives the requirement from client and write codes accordingly, once he completes the code he perform a commit, A commit is a milestone a develpers has achieved and mark it as it is accomplished. if developer want to re arrange commit history as per requirement or need then it is a source code management.
You cannot change order of first commit, so 4 commits is remaining which can be re arranged.
#git rebase -i HEAD~4
it will open in interactive mode, go to insert mode and rearrange lines as per requirement.
save it.
git log --oneline (rearranged)
Git status
c:\git status (it shows the status of the file, either it is untracked/staging area or committed)
D:\project1\git add file1.txt (git add . (all files inclusive modified) ), file in green colour
D:\project1\git commit -m "version1" (File move from staging to repository/commit with label "version1", git will assign a commit number)
branch names on both local and remote repository is master. run git status.
File Editing/Modified: when developer make changes in code/file than file status will become untracked which need to move to staging and commit.
open file1.txt and make some changes and save it.
D:\project1\git add file1.txt
D:\project1\git commit -m "file1_version2"
file1 has two commits after editing,
In version 2 commit, head is pointing to local repository version2
In version 1 commit, head is pointing to remote repository version1 (origin/master).
now head on both local and remote repositoiries on different level. need to perform push/commit with remote repository.
D:\project1\git push origin master.
D:\project1\git log
now head on both local remote repositories are on same level or version2.
Git Reset It will move file from staging area back to untracked area. File2 is at staging area.
D:\project1\git reset file2.txt (file at staging area, requied to make changes and reversing to untracked area).
file moved to untracked area.
Remove Commit:
Selective Commit: if there are several files in staging area and want to commit selective files.
Remove git versioning from project
To start a versioning system in the folder we run D:\project\git init
To remove run D:\project rd /s /q .git from the specified project folder.
git init: creating a new repository.
git clone: to copy or check out the working repository.
git pull: fetch the code already in the repository.
git push: sending the changes to the master branch.
git add: It adds file changes in an existing directory to index.
git commit –m [type in a message] — It is used to snapshot or record a file.
git diff [first branch] [second branch] — it is used to display the differences present between the two branches.
git rest [commit] — It is used to undo all the changes that have been incorporated as a part of a commit after a specified commit has taken place.
git reset –hard [commit] — This command is used to discard all the history and takes us to the last specified commit.
git log –follow [file] — his is similar to that of git log with the additional difference that it lists the version history for a particular file.
git show [commit] — This is used to display the metadata and all the content related changes of a particular commit.
git tag [commitID] — This is used to give particular tags to the code commits. git branch [branch-name] — This is used to create a new branch.
git branch –d [branch name] — It is used to delete the current branch name specified.
git checkout [branch-name] — It is helpful in switching from one branch to another.
git status: To know the comparison between the working directories and index.
Code
Code
Code
Code
Code
Code
Interview
Explain the difference between rebasing and merge in Git?
Git rebase is a command that allows developers to integrate changes from one branch to another.
Git merge is a command that allows you to merge branches from Git. Git rebase and merge both integrate changes from one branch into another. Where they differ is how they used. Git rebase moves a feature branch into a master. Git merge adds a new commit, preserving the history. (If you’re working alone or on a small team, use rebase. If you’re working with a big team, use merge.)
Have you faced the situation where you resolve conflicts in Git? How?
A merge conflict is an event that takes place when Git is unable to automatically resolve differences in code between two commits. Git can merge the changes automatically only if the commits are on different lines or branches. Here are the steps that will help you resolve conflicts in Git: 1. The easiest way to resolve a conflicted file is to open it and make any necessary changes 2. After editing the file, we can use the git add a command to stage the new merged content 3. The final step is to create a new commit with the help of the git commit command 4. Git will create a new merge commit to finalize the merge
How to revert a commit that has already been pushed and made public?
There are two processes through which you can revert a commit: 1. Remove or fix the bad file in a new commit and push it to the remote repository. Then commit it to the remote repository using: git commit –m “commit message” 2. Create a new commit to undo all the changes that were made in the bad commit. Use the following command: git revert <commit id>
Tell about the commands git reset — mixed and git merge — abort?.
git reset — mixed is used to undo changes made in the working directory and staging area.
git merge — abort helps stop the merge process and return back to the state before the merging began.
How will you find a list of files that has been modified in a particular commit?
The command to get a list of files that has been changed in a particular commit is: git diff-tree –r {commit hash} • -r flag allows the command to list individual files • commit hash lists all the files that were changed or added in the commit.
How will you fix a broken commit? What command you will use?
To fix a broken commit in Git, We use the “git commit — amend” command, which helps us combine the staged changes with the previous commits instead of creating a fresh new commit.
Explain git stash drop?
Git ‘stash drop’ command is used to remove the stashed item. This command will remove the last added stash item by default, and it can also remove a selected item as well. Ex: If you want to delete item named stash@{manoj}; you can use the command: git stash drop stash@{manoj}.
Explain about “git cherry-pick”?
This command enables you to pick up commits from a branch within a repository and apply it to another branch. This command is useful to undo changes when any commit is accidentally made to the wrong branch. Then, you can switch to the correct branch and use this command to git cherry-pick the commit.
Can you tell the difference between git pull and git fetch?
Git pull command pulls new changes or commits from a particular branch from your central repository and updates your target branch in your local repository. (Git pull = git fetch + git merge) Git fetch is also used for the same purpose but it works in a slightly different way. When you perform a git fetch, it pulls all new commits from the desired branch and stores it in a new branch in your local repository. If you want to reflect these changes in your target branch, git fetch must be followed with a git merge.
What is origin in Git?
Origin refers to the remote repository that a project was originally cloned from and is used instead of the original repository’s URL.
What is the difference between resetting and reverting?
git reset changes the state of the branch to a previous one by removing all of the states after the desired commit, git revert does it through the creation of new reverting commits and keeping the original one intact.
What is ‘staging area’ or ‘index’ in Git?
That before completing the commits, it can be formatted and reviewed in an intermediate area known as ‘Staging Area’ or ‘Index’. Every change is first verified in the staging area and then that change is committed to the repository.
What work is restored when the deleted branch is recovered?
The files which were stashed and saved in the stash index list will be recovered back. Any untracked files will be lost. Also, it is a good idea to always stage and commit your work or stash them.
What is Head in Git?
Git maintains a variable for referencing, called HEAD to the latest commit in the recent checkout branch. So if we make a new commit in the repo then the pointer or HEAD is going to move or change its position to point to a new commit.
What is the purpose of branching and its types?
It allows the user to switch between the branches to keep the current work in sync without disturbing master branches and other developer’s work as per their requirements.
Feature branching — A feature branch model keeps all of the changes for a particular feature inside of a branch. When the feature is fully tested and validated by automated tests, the branch is then merged into master.
Task branching — In this branch, each task is implemented on its own branch with the task key included in the branch name. It is easy to see which code implements which task, just look for the task key in the branch name.
Release branching — Once the develop branch has acquired enough features for a release, you can clone that branch to form a Release branch. Creating this branch starts the next release cycle, so no new features can be added after this point, only bug fixes, documentation generation, and other release-oriented tasks should go in this branch. Once it is ready to ship, the release gets merged into master and tagged with a version number.
Basic Git Commands — Refresh your mind once again
git init: creating a new repository.
git clone: to copy or check out the working repository.
git pull: fetch the code already in the repository.
git push: sending the changes to the master branch.
git add: It adds file changes in an existing directory to index.
git commit –m [type in a message] — It is used to snapshot or record a file.
git diff [first branch] [second branch] — it is used to display the differences present between the two branches.
git rest [commit] — It is used to undo all the changes that have been incorporated as a part of a commit after a specified commit has taken place.
git reset –hard [commit] — This command is used to discard all the history and takes us to the last specified commit.
git log –follow [file] — his is similar to that of git log with the additional difference that it lists the version history for a particular file.
git show [commit] — This is used to display the metadata and all the content related changes of a particular commit.
git tag [commitID] — This is used to give particular tags to the code commits. git branch [branch-name] — This is used to create a new branch.
git branch –d [branch name] — It is used to delete the current branch name specified.
git checkout [branch-name] — It is helpful in switching from one branch to another.
git status: To know the comparison between the working directories and index.
Instead of setting up git server and client infrastructure on premises, you can get same service on git hub, it provides online service for central repository and it is managed by git hub organization. it is software as a service just create an account and use it.
Account Creation:
Step1. Create an account with Git-hub: create an account with email and password , access services and create resources like azure, AWS etc.
Step2. Logon to github account and click + sign to create:
Repository:
Click New Repository to create repository:
Give name and choose public (anyone on the internet can see and you choose who can commit) or private (you can choose who can see and commit).
Access repository: To access repository can setup on desktop, https or SSH.
Setup on desktop: download github for windows .exe file and run.
star_project_basic is empty. Add some code (add folder and files created in local repository)
First integrate local repository with remote azure repos.
Integration local repository with azure repo:
Go to local repo and run from folder where you have files: C:\project_alpha\ git remote add origin https://star2024@dev.azure.com/star2024/star_project_basic/_git/star_project_basic
enter the credentials of Azure devops.
Push local repository to azure repo: Go to local repository and run
D:\git push -u origin --all
Refresh the browser, you will see files in contents and check history will show versions.
Click history to check the author who commits.
File Edit: Go to local repository and open file2.txt and make changes, file will come to working directory, move to staging area and commit and then commit with remote origin.
Perform push step to reflect this changes with azure repos.
git push -u origin --all
Branches:
In the above steps we have created two files (File1 & File2) in local respository in master branch, we push both files in remote repository in master branch, we made some changes in file1 and commit in both places. Now we create a branch in local repository.
D:\git branch Check list of branch (there is only one master branch)
D:\git branch branch1 Create Branch in Local repository: (branch will be created with all files of master copied)
D:\git checkout branch1 Go to branch:
Merge: If you make changes in file1 in master branch (move to staging and commit with version4). now if you run git log, head shows version4 in master and version3 in branch, so master is ahead one version with branch1, now perform merge action.
D:\git merge branch1 (you should be in master branch) master branch is sync with branch. still remote branch is behind with local branch.
Push Repositories: Push Local Repository to Remote Repository.
D:\git push -u origin master: sync local master repository with remote master repository only
D:\git push -u origin --all : it will sync all branches with remote repository along with contents.
Pull Repositories: Pull Remote repository to Local repository.
create a file/make changes in remote repository and commit.
Push and Pull Scenario1:
Pull Scenario: Master and branch1 has 2 files (File1 and File2) and 3 versions (Version1, 2, 3).
Modify the file1 in the master branch/ click file 1 and edit, commit "Modified file1.txt or Version4" and save it.
Now in local repository modify file2, add to staging and commit "version5".
Push modified file2 into remote repository: D:\git push -u origin master (it throughs an error that file1 was modified in remote master repository and it was not sync with local repository).
user trying to push a commit which performed after commit performed on remote master repository, so user first pull the commit and than push this commit.
D:\git pull
There are 2 insertions and 1 deletion from the file1. you can also check the modification, Go to Files\File1.txt and click compare.
Perform Push now D:\git push -u origin master
Graphs show how commits were executed.
New user join the project and perform pull request.
user should create a directory in D drive (user2_git) in local computer and perform git init to initialize.
pull the repositories from remote repository D:\user2_git\git pull origin --all
Pull Request/Reviewer approval:
When a user make changes in code in local repository then request goes to reviewer than once it is approved commit takes place. Instead of committing changes directly into remote repository by a user, it required approval from reviewer.
Create a project with public visibility, select agile work item process.
Create a local repository in your computer, create a folder and initialize (git init).
c:\star_agile_project\git branch branch1 (create a branch)
Push local branches with remote, c:\star_agile_project\git push -u origin --all
In repos there are two branches, master and branch1 with file1,file2
make changes in file1 of branch1 (git checkout branch1) and commit -m "Version2".
Merge: merge master branch with branch1, it will update master branch with branch1 where we made changes,
c:\star_agile_project\git checkout master
c:\star_agile_project\git merge branch1
git head is updated with master and branch1 locally but it is a commit behind with remote repository.
setup reviewer: go to project\repo\branch\master and click on three dots and select branch policies. (if a user push from master branch then it first go for review).
enable require a minimum number of reviewers.
if you run c:\star_agile_project\git push -u origin --all (you will get the error).
In branch1 file has been reflected while master is not as we enable reviewer in master branch.
In master branch click pull request or select pull request from repo menu and assign a reviewer.
Login with it-user1 and go to project\repo\pull request\approve and complete. check on main branch and it reflects.
.gitignore: Exclude files to be copied in every commit.
With every commit git creates a complete copy of previous version, it includes all files and folders, If you want to omit or does not want to copy certain files in every commit then define those files in .gigignore file.
create a folder (gitignore_project), create file1, file2,file3,secret1,secret2 text files.
create a .gitignore file and add name secret1.txt & secret2.txt and save it.
git status, it will show only files: .gitignore, file1, file2, file3 only
Move to staging area and commit (version1), File1. File2 and File3 will be copied to version1.
if you create any new files4, file5, file6, file7 .... and you dont want to copy files file5,file7 then open .gitifnore file and add file5 and file7 and save it. Run git status and it will show only file 4 and file6, peform git staging and git commit.
Git Remote Repository / Azure repos using Visual Studio:
Download & Install Microsoft Visual Studio community 2022 in local system. select ASP.NET and web development, Azure development workloads.
Create a new project in visual studio code
select asp.net core web app
Project name = webapplication1
Location = C:\Users\Admin\source\repos
.NET 8.0 (long-term support)
To view project files, go to view and select solution explorer
Create & Integrate Git local repository with Remote Repository (Git or Azure):
Click Git and select Create Git Repository
Select visibility public.
create and push. It will create a local repository and also it push the files into git hub
check in the git hub or go to view and click git repository in visual studio
Make changes in the source code file.
In solution explorer/pages/index.cshtml and make some changes and click save, now it shows red mark.
right click on index.cshtml and git/commit, enter message and click commit all. Now commit is done in local repository.
push the commit to remote repository: Go to view/Git Repository/in local repository outgoing there is 1 message, click push.
Check the changes in github.
Build Application:
Go to Build and click Build WebApplication1.
Publish
Go to Build and click public webapplication1.
To publish it required computing resources, select where it should publish.
Create branches with visual studio
Click view and git changes in visual studio.
drop down and click new branch
Enter name of new branch (branch1), select based on master branch and select checkout branch
Go to view/git repository and in local reposditory you can see two branches (master & branch1)
push local branch to remote repository: In branch1 click push
branch1 will appear in remote repository.
TFVC:
Azure Repos uses either Git or TFVC for version control. Team Foundation Version Control is a central versioning system while Git is a distributed version control system.
This service is discontinued.
Azure Repos Fork
It is a complete copy of a repository, including all files, comits, and (optionally) branches.
The new fork acts as if someone cloned the original repository, then pushed to a new empty repository.
After fork has been created, new files, folders, and banches are not sharedbetween the repositories nless a pull request carries them along.
Create a fork: clik on fork.
Enter name and select branches to be copied.
drop down the repository and you can view folk repository. symbols is different than normal repository.
Create a file in the fork repository by creating a task.
go to boards/new work item/task
Title=add a new file
asigned = user
save it.
Go to Repos/fork repository/ click three dots and click create a file
file4.txt (In real time a code file is created/uploaded)
add content/commit
Work item to link: select above created task. and click commit
These changes has been made in fork repository and no change in original repository.
Replicate the changes to original repository, need to create a pull request.
Create a pull request along with a reviewer who will approve this request.
click on Create a pull request in fork repository,
Enter required details, enter reviewer details, work item to link, and create.
Reviewer user logged in the system and approve this request.
Go to Repos/pull request where user will approve. complete, complete merge.
Check file4.txt has been added to star_basic_project.
Azure Repos Clone
When you clone a repository than a copy will be created in local computer.
Create a project in azure devops and push files to repos.