MOST IMPORTANT GIT COMMANDS



Let’s understand Git with a hypothetical example of Tom. Tom is a newbie to Git, he has no experience with it before but his team uses Git and the code is hosted on remote server. He needs to collaborate with other coders. Let us see how Tom would accomplish this, 




  1. git-clone-- The first step is to get the local copy of the remote code base into Tom’s computer; Tom selects the location in his local computer to clone the remote repository. He goes to that location and runs the command “git clone ”. Doing so results in all the code contents in the remote repo getting cloned or copied file to file in Tom’s local computer. He know has his own version of code to play around with.




  2. git branch- Before starting the work, right after closing the repository he checks which branch he is working with, the command for that is “git branch”. He gets to know that the branch is master, marked with a star, which contains the exact copy of the remote repo he had cloned. To create a new branch Tom runs a command “git branch xyz”. After Tom has run the command he’s able to now see two branches, both of them seemed to have the same code of remote repo but the size of local folder has not doubled. This is git magic! On looking closely Tom finds that there is a folder named .git created in a local location where he cloned the repository.




  3. git checkout - There are 2 additional branches created apart from the original master branch. In xyz one file got added and one get removed. This command is able to keep a track of the current status of the branch just maintaining the info about the diff. that is the difference between the original branch.




  4. git add - We can add files by a command “git add followed by the file path” to add files in staging area .




  5. git-status- It give us an idea about the git status. It tells us how the current branch differs from the original branch. It gives information on what changes are unstaged and  staged? 




  6. git commit –m ‘commit message’-  commit are checkpoints to the code history of your repository where in Code changes  that are grouped in some or the other way.




  7. git merge- it merges the independent branches into one single branch.




  8. Git push origin - it is used to upload the local repository content to the remote repository.




 

Editor: MUSKAN GUPTA Added on: 2020-05-27 19:26:50 Total View:410







Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---