Overview of GIT and Important commands of GIT in Linux
Git is another code based repository like SVN, CVS etc.. . Although at the beginning it might be little tough than SVN which is very easy to learn but if you are thinking to work at higher level where you can control your code at multiple level then Git is the good way and you can start using Git. I am putting some of the features of git which makes it great.
Features/Advantage of Git:
*. Decentralized Repository:
Decentralized Repository means repository will be available on local machine as well as actual servers. Which gives us the flexiblity that we can commit our code to our local repository even we are not connected to live repository. Suppose you don’t have internet connection available still you can commit your changes to your local repository and once you get internet connection you can push those changes to main server (remote repository).So we can say Git has high availablity.
*. Fast Process:
Since it works locally (local branches ) so its faster than SVN.
*. Only one .git file per repository: Unlike svn where there is a .svn file gets created at each subfolder. Git creates only one .git file per repository.
*. Better ignore file:
There is a single .gitignore file which contains complete list of files which we want that git should ignore while doing commit or update of files. Since complete ignore file list is available on single file so its easy to see or edit the file and make necessary changes based on requirement. SVN doesn’t have such easy way to manage ignore files.
*collaboration Friendly:
Git makes it easy to share/collaborate code from/ to various group of contributors. There are some good platforms are also doing better in this area like github.
*. Easily work within multiple branches:
With git we can create multiple branch on same system and each branch might have different version of code. Suppose you want to test something like can i achieve my goal through this way?
If yes then i would like to go with that and if not then i can choose another way to do that. So with Git we can easily create a test branch which will have testing code available and once we become sure then we can change the branch and go to actual branch and make same code there. Such way we can avoid unnecessary code on remote repository as well as our projects.
Some Basic commands of Git to get started with it:
After installing git on your sytem you might need to configure few things so that Git repository can undersand who you are and what is your identity. For this purpose you need to run below command on your linux command line
*.git config –global user.name “username” =======> Through this command you can let your repository know that who you are what is your username. I mean once you will commit any changes your repository will use this username for other contributors.
*. git config –global user.email email@email.com ====> Through this command we are configuring the email address of the developers so that if Git admin wants to contact to that person he can see the users email as well for future purpose.
*. git status => Through this command we got to know if the repository is uptodate or not. If repository is not upto date then it will show the list of files which are unversioned.
For example: git status
git status -s
*. git add => adds file contents or folder to the repository
git add abc.php => Add abc.php file
git add abc =>add abc folder to repository
*. git branch=>It will show how many branches are avaialable on repository. Branch name with * mark is actually the current active branch.
*. git branch –BRANCHNAME–:- Create a new banch with name –BRANCHNAME– and switch to that new branch.
*. git checkout —BRANCHNAME– :- Switch among branches . Sappose we are on one branch and want to switch under another branch then
*. git commit -m “message” : commit changes to repository (locally)
*. git push origin –BRANCHNAME– =>
this command will push changes of your local repository to remote server repository. By default origin means remote server. –BRANCHNAME– is the name of the local branch name on your computer so that only code of that branch will get added to remote repository.
*. git pull origin –BRANCHNAME– => through this command basically we fetch the files from remote repository to our local machine.
*. git fetch origin –BRANCHNAME–:–BRANCHNAME–
i) it will create brach on another local repository named –BRANCHNAME–
ii) pull changed code
*. git branch -D –BRANCHNAME– => To delete a branch from local repository
Note:
*. You can’t recieve code from one branch to another branch..
Chandra Shekhar
Latest posts by Chandra Shekhar (see all)
- Best practices for micro service design - January 23, 2022
- Spring Boot - January 23, 2022
- Java - January 23, 2022
Recent Comments