A Guide to Git: The Fundamentals by Nilay Majorwar Programming Club, IIT Kanpur

Because you have the entire history of the project right there on your local disk, most operations seem almost instantaneous. Instead, Git thinks of its data more like a series of snapshots of a miniature filesystem. With Git, every time you commit, or save the state of your git fundamentals project, Git basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot. To be efficient, if files have not changed, Git doesn’t store the file again, just a link to the previous identical file it has already stored.

  • Git development began in early 2005, when Linus and fellow Linux maintainers discontinued the use of the then source control management system (SCM), namely BitKeeper.
  • It also tells us that we have some “unmerged paths”—that we’re currently mid-merge and we need to fix the conflicts.
  • GitHub takes care of this problem by keeping track of all the changes that have been pushed to the repository.
  • You can now change this new branch independently of the original branch.
  • Showing the butler your changes when you renamed Emma to Clara is simply making a commit of your work.
  • This remote was automatically setup for us when we ran git clone.

When changes areStart done in the same file by different developers then conflict occurred. To solve this, you need to first identify the lines of code which is conflicting then make the necessary changes, and commit the changes to the repository. It is also comes with GitHub, ability to collaborate with other developers from any location. Now that we’ve changed the remote branch, our teammate would need to do a git pull to merge in our new merged changes.

How to stage changes in Git

Said another way, we want to take the current state of main and add in our changes from the chapter-2 branch. We’re currently on the main branch locally, so we need to tell GitHub to update its own main with the new commit that we made. We have a new commit on our local machine and we need to update our “source of truth”—the origin remote—aka GitHub. Continuing with our book analogy, let’s make a new file called chapter-1.txt and insert a sentence into it.

git fundamentals

It consists of applying an arbitrary commit of another branch but merging the differences if needed. The following porcelain commands are widely used, which manipulate the Git references under the hood. After adding blobs to the index, we can group them into a tree structure which is ready to be promoted. Commonly, after working on various files/blobs, we are ready to share them and sign our names for the final work.

Branching and Merging

As you can see in the above image, it says that our remote’s name is origin. As you can see in the above picture, my repository name is “My-GitHub-Project” and this command made me go to that specific directory. Pick a name for your first repository, add a small description, check the ‘Initialize this repository with a README’ box, and click on the “Create repository” button. Type 1 involves creating a totally fresh repository on GitHub, cloning it to our computer, working on our project, and pushing it back. Today, when searching for new recruits for their projects, most companies look at GitHub profiles.

  • This tool is a version control system that was initially developed to work with several developers on the Linux kernel.
  • The version found here has been updated with corrections and additions from hundreds of contributors.
  • So Git does not necessarily rely on a central server to store all the versions of a project’s files.
  • The importance of Git is nowhere second to learning to write code.
  • We’re currently on the main branch locally, so we need to tell GitHub to update its own main with the new commit that we made.

Git also helps you synchronise code between multiple people. Now Git takes those changes you and your friend made independently and merges them to a single “Master” repository. So by using Git you can ensure you both are working on the most recent version of the repository. So you don’t have to worry about mailing your files to each other and working with a ridiculous number of copies of the original file. Currently a remote named origin has been added, now we will push our local master branch to the remote. Git merge command is used to merge 2 branches, in our case we have 2 branches master and registration with different sets of files.

A Guide to Git: The Fundamentals

This operation is safe even if Alice has uncommitted local changes. The range notation HEAD..FETCH_HEAD means “show everything that is reachable
from the FETCH_HEAD but exclude anything that is reachable from HEAD”. Alice already knows everything that leads to her current state (HEAD),
and reviews what Bob has in his state (FETCH_HEAD) that she has not
seen with this command. This command ensures that the changes in the experimental branch are
already in the current branch.

If you’re looking out for a Git tutorial for beginners, then you’ve ended up at the right place. By the end of this Git tutorial, you will have a strong understanding of how Git & Github works and how to use them effectively in your projects. This Git tutorial on Webdesigner Depot is geared towards web designers. A conflict occurs when merging two changes that have changed the same line in a file. If two commits have changed the same line in a file, Git doesn’t know which commit’s changes to use, and it will require you to make the choice.


Leave a Reply

Your email address will not be published. Required fields are marked *