How to: Use Git (Git Clone, Git Fetch, Git Pull, Git Clone & Git Rebase)

How to: Use Git (Git Clone, Git Fetch, Git Pull, Git Clone & Git Rebase)

I am new to Git and using repositories in Linux based systems (Being a Visual Studio / Team Foundation guy is not like I am starting from scratch). The point was just to understand what does each command does so I can adequately make and get updates of the code. If anything I still fear I am going to screw up but thus far this is what I have gathered from the Internet and the git man page.

Git Clone

This is where it all begins. Git clone allows you to clone an existing repository into a newly crated directory in your local machine. This creates a new origin for the repository creating a local branch out of the active branch which is generally master.

Git Fetch

As the name implies this will fetch the latest version of a given branch. It will not do any merging and if you want to work on it you should perform a checkout of the branch. Think of this as getting a local copy of a remote branch which will overwrite whatever you have.

Git Pull

Similar to Fetch it will get the latest version of a given branch but this time it will merge with what you have. So if you want to keep your changes you will use a Pull while Fetch will get rid of them (good for when you’ve messed something up right? lol.)

Git Rebase

From what I understand this is like a Git Pull but cooler (unless it is the same thing but I didn’t get that.) What it will do is analyse the changes you’ve made to the branch and record them in a temporary area. Then it will perform a pull from the server with the latest information and once it is done it will replay the changes you had made into the latest version of the branch. The advantage here is that the changes you’ve made can be applied to newer versions. It is like doing a pull request locally to a branch.

As a new user to version control and Git could gather, it can get pretty confusing. Just get a test repository and play with the commands so you can see how they work. And remember, if you mess something up version control is there to allow you to revert changes so for the most time you are in safe territory… but be careful nonetheless.

Enhanced by Zemanta

Leave a Reply