Introduction to version control system (VCS)
Version control systems are used to control the changes to the files. With VCS, we can easily find out who changed which files and when. We can also recover the files at certain point of time in the past. There are mainly 2 types of version control systems as mentioned below.
Before GIT came up, we had a centralized version control systems like SVN, ClearCase which stored the versions of the files on central server. The issue with the centralized VCS is that if the server goes down, we can not check out the files from the server and we are blocked. Distributed VCS like GIT solves this problem by having the entire repository on the client machines. No matter if server is down or up, you can keep working on your local copy of the files and later push your changes to the server. Multiple people can work on different branches of the repository and merge these branches later which is not possible in case of centralized VCS.
What is GIT?
GIT is free distributed version control tool that can be used to manage any software project of any size.
There are 3 states of project in GIT.
When we modify any files, we need to add it to the staging area. Then we need to commit the files to the git directory.
What are the features of GIT?
GIT offers many features that are not available in other version control tools like SVN, Clear Case etc.
GIT with GITHUB
http://rogerdudler.github.io/git-guide/
GIT with Stash
Stash is used to manage GIT repositories.
Common Questions / Issues in GIT
Version control systems are used to control the changes to the files. With VCS, we can easily find out who changed which files and when. We can also recover the files at certain point of time in the past. There are mainly 2 types of version control systems as mentioned below.
- Centralized version control system (SVN, Clear Case, Perforce)
- Distributed version control system (GIT, Mercurial, Bazaar, Darcs, BitKeeper)
Before GIT came up, we had a centralized version control systems like SVN, ClearCase which stored the versions of the files on central server. The issue with the centralized VCS is that if the server goes down, we can not check out the files from the server and we are blocked. Distributed VCS like GIT solves this problem by having the entire repository on the client machines. No matter if server is down or up, you can keep working on your local copy of the files and later push your changes to the server. Multiple people can work on different branches of the repository and merge these branches later which is not possible in case of centralized VCS.
What is GIT?
GIT is free distributed version control tool that can be used to manage any software project of any size.
There are 3 states of project in GIT.
- Working Directory
- Staging Area (index)
- Git Directory
When we modify any files, we need to add it to the staging area. Then we need to commit the files to the git directory.
What are the features of GIT?
GIT offers many features that are not available in other version control tools like SVN, Clear Case etc.
- Distributed
- Branching
- Merging
- Staging Area
- Multiple Workflows
- Cloning
- Re-basing
GIT Installation and set up
GIT can be installed from the official website. Once GIT is installed you can fire below commands to set up the user for the GIT commands.
To see your settings are applied correctly, execute below command.
Frequently used GIT commands
GIT has got many commands as mentioned below.- git config --global user.name "G Bush"
- git config --global user.email gbush@washington.com
To see your settings are applied correctly, execute below command.
- git config user.email
- git config user.name
To view all keys, you can use below command.
- git config --list
To view the help for any command (verb), use below command.
- git help config
- git help <verb>
- git help <add>
To clone the repository from server, you can use below command.
- git clone <url>
To track new files, to stage the modified files and to mark the files to be staged after merge conflict , we use below command.
- git add <file name>
To remove the file from git, fire below command.
- git rm <file name>
- git rm cached <file name>
To view who committed what and when, use below command.
- git log --pretty=format:"%h - %an, %ar : %s"
To unstage file, use below command.
- git reset HEAD <file name>
To discard the changes in file, use below command.
- git checkout -- <file name>
- Stash or branch them
To view remote repositories that are configures, use below command.
- git remote -v
Frequently used GIT commands
- git -init #Initializes empty git repository in current directory.
- git status #Check the status of the project
- git add xyzfile #add a file into the repository to track in staging area.
- git commit -m "comments" #commit a file from staging area to repository.
- git add '*.txt' #add all text files into staging area.
- git log #to view our commit history
- git remote add origin https://github.com/xyz.git #to add remote repository
- git push #commit changes to remote repository
- git pull #pull changes from the remote repository
- git diff head #view differences from last commit.
- git diff --staged #view changes that are to be committed
- git reset filenamexyz #remove file from staging area
- git checkout -- octocat.txt #get rid of last changes in the file
- git branch ABC #creates the branch with name ABC
- git branch #shows total branches
- git checkout ABC #switches to the branch with name ABC
- git rm '*.txt' #remove all files from current branch and disk as well
- git merge ABC #merge changes from branch ABC to Master barnch
- git branch -d ABC #delete the branch ABC
- git remote add <custom name of repo> <url of repo>
- git push --set-upstream <nameofrepo-say-testrepo> <nameofbranch-say-master >
To pull the changes from the repository, you need to use below command.
- git remote add <custom name of repo-say-testrepo> <url of repo>
- git pull <nameofrepo-say-testrepo> <nameofbranch-say-master>
GIT with GITHUB
http://rogerdudler.github.io/git-guide/
GIT with Stash
Stash is used to manage GIT repositories.
Common Questions / Issues in GIT
- How to recover the last committed file ?
- How to untrack the file that's currently being tracked?
- I do not want to push some files - git update-index --assume-unchanged Localization/el-GR.js
- I do not want to pull some files like .csproj and settings.settings and references
- git update-index --no-assume-unchanged .gitignore
What do you think on this topic? Please express your opinion or ask any question through comment below. You can write to me at reply2sagar@gmail.com
No comments:
Post a Comment
Leave your valuable feedback. Your thoughts do matter to us.