How does git work




















This will create a remote repository in GitHub, and when you open the repository, a page like the image below will open up:. In order to push all the code from the local repository into the remote repository, use the following command:. This pushes the code from the master branch in the local repository to the master branch in the remote repository. The remote repository code is updated continuously by various developers, hence git pull is necessary:.

The command for this is:. I will soon be publishing one more article on slightly more advanced concepts of Git. Stay tuned! I love technology and follow the advancements in technology. I also like helping others with any knowledge I have in the technology space. If you read this far, tweet to the author to show them you care. Tweet a thanks. Learn to code for free. Get started. Forum Donate. Aditya Sridhar. Let me break it down and explain the wording: Control System: This basically means that Git is a content tracker.

So Git can be used to store content — it is mostly used to store code due to the other features it provides. Version Control System : The code which is stored in Git keeps changing as more code is added. Also, many developers can add code in parallel. So Version Control System helps in handling this by maintaining a history of what changes have happened. Also, Git provides features like branches and merges, which I will be covering later.

Distributed Version Control System : Git has a remote repository which is stored in a server and a local repository which is stored in the computer of each developer. I will explain the concept of remote and local repositories later in this article. Why a Version Control System like Git is needed Real life projects generally have multiple developers working in parallel. Go into your project folder and add a local Git repository to the project using the following commands: cd simple-git-demo git init The git init command adds a local Git repository to the project.

Staging and Committing the code Committing is the process in which the code is added to the local repository. Staging Use the following command for staging the file: git add demo. Use this carefully since it adds all the files and folders in your project to the staging area. Refs to the rescue! A reference is simply a file stored in. Let's go ahead and commit our myfile. Go ahead and run git add myfile.

Now, let's navigate to the. From there, run cat master. You should see the SHA Finally, run git log -1 master which should output something similar to the following:.

As you can see, branches are simply just references. Likewise, creating a new branch creates a new reference file with the commit hash. Helpful hint: If you ever want to see all references, run git show-ref , which will list all references. HEAD is a symbolic reference. Well, the HEAD file is usually a symbolic reference to your current branch. You might be thinking to yourself, "You keep saying symbolic ; what does that mean? Symbolic means that it contains a pointer to another reference.

If your head is spinning, I'm with you. Here is a great analogy, pulled from this website. A good analogy would be a record player and the playback and record keys on it as the HEAD. As the audio starts recording, the tape moves ahead, moving past the head by recording onto it.

The stop button stops the recording while still pointing to the point it last recorded, and the point that record head stopped is where it will continue to record again when Record is pressed again. If we move around, the head pointer moves to different places; however, when Record is pressed again, it starts recording from the point the head was pointing to when Record was pressed.

This makes sense because we are on the master branch. HEAD is, essentially, always going to be the reference to the last commit in the currently checked-out branch. We have covered a lot in this post! We've learned a bit of fun history regarding how Git came about and examined the main plumbing that makes all of the magic happen! If you want to continue to dive deeper into Git, as well as better understand how some of the common commands work, I highly recommend the book titled "Pro Git", which is available for free here.

Honeybadger has your back when it counts. We're the only error tracker that combines exception monitoring, uptime monitoring, and cron monitoring into a single, simple to use platform. Our mission: to tame production and make you a better, more productive developer.

Learn more. Julie is an engineer at Stitch Fix. In her free time, she likes reading, cooking, and walking her dog. Join our community of kick-ass developers as we learn engineering, DevOps, cloud architecture, and bootstrapping remote software companies. We're Honeybadger. We'll never send you spam; we will send you cool stuff like exclusive content, memes, and special swag.

We're working on something new! Hook Relay gives you Stripe-quality webhooks in minutes. When you want Git to track changes you've made to a certain file, you must add it to the staging area. Git recognizes when you modify a file but doesn't track it unless you stage it.

The staging area represents a layer of security, allowing you to review the changes before committing them. Being in the staging area is a prerequisite for files to be later committed, i. You can check which files Git tracks by running:. Note: You can make staging faster and stage all files in your working directory by running the git add. If you change your mind, you can remove a file from the staging area. To unstage a file , use the following syntax:.

A commit represents a save point for your work, a snapshot of your code at a particular point in time. Adding files to the staging area means that they are ready to be committed.

Each commit should have a description specified after the -m flag, which will later help you know what the commit was about. The output shows a log of all the commits you have made, who made the commit, the date, and the commit notes. Adding the --oneline flag shows the commit history condensed in one line. Omitting the flag shows a detailed commit history.

If you have made mistakes during your project development or want to revert a commit for any reason, git revert allows you to do so. The git revert command reverts a particular commit, i. Note: The git revert command doesn't remove the commit from commit history. It only adds a new commit specifying that it has reverted the specified commit. Find commit IDs by running git log. The 7-character code is the commit ID. The git reset command permanently takes you back to a certain point in development.

All the files and changes added after that point in time are unstaged if you want to re-add them. Specifying the --hard flag removes the unstaged files, making it impossible to bring them back. A fork is a complete copy of an existing repository that allows you to make changes and experiment without affecting the original project. Forking is a way for someone to propose changes to an existing project, or it can be a starting point for a project of your own if the code is open source.

If you want to propose a change or a bug fix for a project, you can fork a repository, make the fix, and make a pull request to the project owner. Sign in to your GitHub account. Wait for the forking process to complete. When it finishes, you will have a copy of the repository on your GitHub account. The next step is to take the repository URL from the Code section and clone the repository to your local machine. In this example, we have created a fork of the springmvc-raml-plugin repository, and now we are free to implement our changes or start building a new plugin on top of the existing one.

Branching is a feature in Git that allows developers to work on a copy of the original code to fix bugs or develop new features. By working on a branch, developers don't affect the master branch until they want to implement the changes. The master branch generally represents the stable version of your code, which is released or published. That's why you should avoid adding new features and new code to the master branch if they are unstable.

Branching creates an isolated environment to try out the new features, and if you like them, you can merge them into the master branch.



0コメント

  • 1000 / 1000