How To Do What You Love
January 2006 To do something well you have to like it. That idea is not exactly novel. We've got it down to four words: "Do what you love." But it's not enough just to tell people that. Doing what you love is complicated. The very idea is foreign to what most of us learn as kids. When I was a kid, it seemed as if work and fun were opposites by definition. Life had two states: some of the time adults were making you do things, and that was called work; the rest of the time you could do what you wanted, and that was called playing. Occasionally the things adults made you do were fun, just as, occasionally, playing wasn't — for example, if you fell and hurt yourself. But except for these few anomalous cases, work was pretty much defined as not-fun. And it did not seem to be an accident. School, it was implied, was tedious because it was preparation for grownup work. The world then was divided into two groups, grownups and kids. Grownups, like some kind of cursed race, had to work. Kids didn't, but they did have to go to school, which was a dilute version of work meant to prepare us for the real thing. Much as we disliked school, the grownups all agreed that grownup work was worse, and that we had it easy. Teachers in particular all seemed to believe implicitly that work was not fun. Which is not surprising: work wasn't fun for most of them. Why did we have to memorize state capitals instead of playing dodgeball? For the same reason they had to watch over a bunch of kids instead of lying on a beach. You couldn't just do what you wanted. I'm not saying we should let little kids do whatever they want. They may have to be made to work on certain things. But if we make kids work on dull stuff, it might be wise to tell them that tediousness is not the defining quality of work, and indeed that the reason they have to work on dull stuff now is so they can work on more interesting stuff later. [1] Once, when I was about 9 or 10, my father told me I could be whatever I wanted when I grew up, so long as I enjoyed it. I remember that precisely because it seemed so anomalous. It was like being told to use dry water. Whatever I thought he meant, I didn't think he meant work could literally be fun — fun like playing. It took me years to grasp that. Jobs By high school, the prospect of an actual job was on the horizon. Adults would sometimes come to speak to us about their work, or we would go to see them at work. It was always understood that they enjoyed what they did. In retrospect I think one may have: the private jet pilot. But I don't think the bank manager really did. The main reason they all acted as if they enjoyed their work was presumably the upper-middle class convention that you're supposed to. It would not merely be bad for your career to say that you despised your job, but a social faux-pas. Why is it conventional to pretend to like what you do? The first sentence of this essay explains that. If you have to like something to do it well, then the most successful people will all like what they do. That's where the upper-middle class tradition comes from. Just as houses all over America are full of chairs that are, without the owners even knowing it, nth-degree imitations of chairs designed 250 years ago for French kings, conventional attitudes about work are, without the owners even knowing it, nth-degree imitations of the attitudes of people who've done great things. What a recipe for alienation. By the time they reach an age to think about what they'd like to do, most kids have been thoroughly misled about the idea of loving one's work. School has trained them to regard work as an unpleasant duty. Having a job is said to be even more onerous than schoolwork. And yet all the adults claim to like what they do. You can't blame kids for thinking "I am not like these people; I am not suited to this world." Actually they've been told three lies: the stuff they've been taught to regard as work in school is not real work; grownup work is not (necessarily) worse than schoolwork; and many of the adults around them are lying when they say they like what they do. The most dangerous liars can be the kids' own parents. If you take a boring job to give your family a high standard of living, as so many people do, you risk infecting your kids with the idea that work is boring. [2] Maybe it would be better for kids in this one case if parents were not so unselfish. A parent who set an example of loving their work might help their kids more than an expensive house. [3] It was not till I was in college that the idea of work finally broke free from the idea of making a living. Then the important question became not how to make money, but what to work on. Ideally these coincided, but some spectacular boundary cases (like Einstein in the patent office) proved they weren't identical. The definition of work was now to make some original contribution to the world, and in the process not to starve. But after the habit of so many years my idea of work still included a large component of pain. Work still seemed to require discipline, because only hard problems yielded grand results, and hard problems couldn't literally be fun. Surely one had to force oneself to work on them. If you think something's supposed to hurt, you're less likely to notice if you're doing it wrong. That about sums up my experience of graduate school. Bounds How much are you supposed to like what you do? Unless you know that, you don't know when to stop searching. And if, like most people, you underestimate it, you'll tend to stop searching too early. You'll end up doing something chosen for you by your parents, or the desire to make money, or prestige — or sheer inertia. Here's an upper bound: Do what you love doesn't mean, do what you would like to do most this second. Even Einstein probably had moments when he wanted to have a cup of coffee, but told himself he ought to finish what he was working on first. It used to perplex me when I read about people who liked what they did so much that there was nothing they'd rather do. There didn't seem to be any sort of work I liked that much. If I had a choice of (a) spending the next hour working on something or (b) be teleported to Rome and spend the next hour wandering about, was there any sort of work I'd prefer? Honestly, no. But the fact is, almost anyone would rather, at any given moment, float about in the Carribbean, or have sex, or eat some delicious food, than work on hard problems. The rule about doing what you love assumes a certain length of time. It doesn't mean, do what will make you happiest this second, but what will make you happiest over some longer period, like a week or a month. Unproductive pleasures pall eventually. After a while you get tired of lying on the beach. If you want to stay happy, you have to do something. As a lower bound, you have to like your work more than any unproductive pleasure. You have to like what you do enough that the concept of "spare time" seems mistaken. Which is not to say you have to spend all your time working. You can only work so much before you get tired and start to screw up. Then you want to do something else — even something mindless. But you don't regard this time as the prize and the time you spend working as the pain you endure to earn it. I put the lower bound there for practical reasons. If your work is not your favorite thing to do, you'll have terrible problems with procrastination. You'll have to force yourself to work, and when you resort to that the results are distinctly inferior. To be happy I think you have to be doing something you not only enjoy, but admire. You have to be able to say, at the end, wow, that's pretty cool. This doesn't mean you have to make something. If you learn how to hang glide, or to speak a foreign language fluently, that will be enough to make you say, for a while at least, wow, that's pretty cool. What there has to be is a test. So one thing that falls just short of the standard, I think, is reading books. Except for some books in math and the hard sciences, there's no test of how well you've read a book, and that's why merely reading books doesn't quite feel like work. You have to do something with what you've read to feel productive. I think the best test is one Gino Lee taught me: to try to do things that would make your friends say wow. But it probably wouldn't start to work properly till about age 22, because most people haven't had a big enough sample to pick friends from before then. Sirens What you should not do, I think, is worry about the opinion of anyone beyond your friends. You shouldn't worry about prestige. Prestige is the opinion of the rest of the world. When you can ask the opinions of people whose judgement you respect, what does it add to consider the opinions of people you don't even know? [4] This is easy advice to give. It's hard to follow, especially when you're young. [5] Prestige is like a powerful magnet that warps even your beliefs about what you enjoy. It causes you to work not on what you like, but what you'd like to like. That's what leads people to try to write novels, for example. They like reading novels. They notice that people who write them win Nobel prizes. What could be more wonderful, they think, than to be a novelist? But liking the idea of being a novelist is not enough; you have to like the actual work of novel-writing if you're going to be good at it; you have to like making up elaborate lies. Prestige is just fossilized inspiration. If you do anything well enough, you'll make it prestigious. Plenty of things we now consider prestigious were anything but at first. Jazz comes to mind — though almost any established art form would do. So just do what you like, and let prestige take care of itself. Prestige is especially dangerous to the ambitious. If you want to make ambitious people waste their time on errands, the way to do it is to bait the hook with prestige. That's the recipe for getting people to give talks, write forewords, serve on committees, be department heads, and so on. It might be a good rule simply to avoid any prestigious task. If it didn't suck, they wouldn't have had to make it prestigious. Similarly, if you admire two kinds of work equally, but one is more prestigious, you should probably choose the other. Your opinions about what's admirable are always going to be slightly influenced by prestige, so if the two seem equal to you, you probably have more genuine admiration for the less prestigious one. The other big force leading people astray is money. Money by itself is not that dangerous. When something pays well but is regarded with contempt, like telemarketing, or prostitution, or personal injury litigation, ambitious people aren't tempted by it. That kind of work ends up being done by people who are "just trying to make a living." (Tip: avoid any field whose practitioners say this.) The danger is when money is combined with prestige, as in, say, corporate law, or medicine. A comparatively safe and prosperous career with some automatic baseline prestige is dangerously tempting to someone young, who hasn't thought much about what they really like. The test of whether people love what they do is whether they'd do it even if they weren't paid for it — even if they had to work at another job to make a living. How many corporate lawyers would do their current work if they had to do it for free, in their spare time, and take day jobs as waiters to support themselves? This test is especially helpful in deciding between different kinds of academic work, because fields vary greatly in this respect. Most good mathematicians would work on math even if there were no jobs as math professors, whereas in the departments at the other end of the spectrum, the availability of teaching jobs is the driver: people would rather be English professors than work in ad agencies, and publishing papers is the way you compete for such jobs. Math would happen without math departments, but it is the existence of English majors, and therefore jobs teaching them, that calls into being all those thousands of dreary papers about gender and identity in the novels of Conrad. No one does that kind of thing for fun. The advice of parents will tend to err on the side of money. It seems safe to say there are more undergrads who want to be novelists and whose parents want them to be doctors than who want to be doctors and whose parents want them to be novelists. The kids think their parents are "materialistic." Not necessarily. All parents tend to be more conservative for their kids than they would for themselves, simply because, as parents, they share risks more than rewards. If your eight year old son decides to climb a tall tree, or your teenage daughter decides to date the local bad boy, you won't get a share in the excitement, but if your son falls, or your daughter gets pregnant, you'll have to deal with the consequences. Discipline With such powerful forces leading us astray, it's not surprising we find it so hard to discover what we like to work on. Most people are doomed in childhood by accepting the axiom that work = pain. Those who escape this are nearly all lured onto the rocks by prestige or money. How many even discover something they love to work on? A few hundred thousand, perhaps, out of billions. It's hard to find work you love; it must be, if so few do. So don't underestimate this task. And don't feel bad if you haven't succeeded yet. In fact, if you admit to yourself that you're discontented, you're a step ahead of most people, who are still in denial. If you're surrounded by colleagues who claim to enjoy work that you find contemptible, odds are they're lying to themselves. Not necessarily, but probably. Although doing great work takes less discipline than people think — because the way to do great work is to find something you like so much that you don't have to force yourself to do it — finding work you love does usually require discipline. Some people are lucky enough to know what they want to do when they're 12, and just glide along as if they were on railroad tracks. But this seems the exception. More often people who do great things have careers with the trajectory of a ping-pong ball. They go to school to study A, drop out and get a job doing B, and then become famous for C after taking it up on the side. Sometimes jumping from one sort of work to another is a sign of energy, and sometimes it's a sign of laziness. Are you dropping out, or boldly carving a new path? You often can't tell yourself. Plenty of people who will later do great things seem to be disappointments early on, when they're trying to find their niche. Is there some test you can use to keep yourself honest? One is to try to do a good job at whatever you're doing, even if you don't like it. Then at least you'll know you're not using dissatisfaction as an excuse for being lazy. Perhaps more importantly, you'll get into the habit of doing things well. Another test you can use is: always produce. For example, if you have a day job you don't take seriously because you plan to be a novelist, are you producing? Are you writing pages of fiction, however bad? As long as you're producing, you'll know you're not merely using the hazy vision of the grand novel you plan to write one day as an opiate. The view of it will be obstructed by the all too palpably flawed one you're actually writing. "Always produce" is also a heuristic for finding the work you love. If you subject yourself to that constraint, it will automatically push you away from things you think you're supposed to work on, toward things you actually like. "Always produce" will discover your life's work the way water, with the aid of gravity, finds the hole in your roof. Of course, figuring out what you like to work on doesn't mean you get to work on it. That's a separate question. And if you're ambitious you have to keep them separate: you have to make a conscious effort to keep your ideas about what you want from being contaminated by what seems possible. [6] It's painful to keep them apart, because it's painful to observe the gap between them. So most people pre-emptively lower their expectations. For example, if you asked random people on the street if they'd like to be able to draw like Leonardo, you'd find most would say something like "Oh, I can't draw." This is more a statement of intention than fact; it means, I'm not going to try. Because the fact is, if you took a random person off the street and somehow got them to work as hard as they possibly could at drawing for the next twenty years, they'd get surprisingly far. But it would require a great moral effort; it would mean staring failure in the eye every day for years. And so to protect themselves people say "I can't." Another related line you often hear is that not everyone can do work they love — that someone has to do the unpleasant jobs. Really? How do you make them? In the US the only mechanism for forcing people to do unpleasant jobs is the draft, and that hasn't been invoked for over 30 years. All we can do is encourage people to do unpleasant work, with money and prestige. If there's something people still won't do, it seems as if society just has to make do without. That's what happened with domestic servants. For millennia that was the canonical example of a job "someone had to do." And yet in the mid twentieth century servants practically disappeared in rich countries, and the rich have just had to do without. So while there may be some things someone has to do, there's a good chance anyone saying that about any particular job is mistaken. Most unpleasant jobs would either get automated or go undone if no one were willing to do them. Two Routes There's another sense of "not everyone can do work they love" that's all too true, however. One has to make a living, and it's hard to get paid for doing work you love. There are two routes to that destination: The organic route: as you become more eminent, gradually to increase the parts of your job that you like at the expense of those you don't. The organic route is more common. It happens naturally to anyone who does good work. A young architect has to take whatever work he can get, but if he does well he'll gradually be in a position to pick and choose among projects. The disadvantage of this route is that it's slow and uncertain. Even tenure is not real freedom. The two-job route has several variants depending on how long you work for money at a time. At one extreme is the "day job," where you work regular hours at one job to make money, and work on what you love in your spare time. At the other extreme you work at something till you make enough not to have to work for money again. The two-job route is less common than the organic route, because it requires a deliberate choice. It's also more dangerous. Life tends to get more expensive as you get older, so it's easy to get sucked into working longer than you expected at the money job. Worse still, anything you work on changes you. If you work too long on tedious stuff, it will rot your brain. And the best paying jobs are most dangerous, because they require your full attention. The advantage of the two-job route is that it lets you jump over obstacles. The landscape of possible jobs isn't flat; there are walls of varying heights between different kinds of work. [7] The trick of maximizing the parts of your job that you like can get you from architecture to product design, but not, probably, to music. If you make money doing one thing and then work on another, you have more freedom of choice. Which route should you take? That depends on how sure you are of what you want to do, how good you are at taking orders, how much risk you can stand, and the odds that anyone will pay (in your lifetime) for what you want to do. If you're sure of the general area you want to work in and it's something people are likely to pay you for, then you should probably take the organic route. But if you don't know what you want to work on, or don't like to take orders, you may want to take the two-job route, if you can stand the risk. Don't decide too soon. Kids who know early what they want to do seem impressive, as if they got the answer to some math question before the other kids. They have an answer, certainly, but odds are it's wrong. A friend of mine who is a quite successful doctor complains constantly about her job. When people applying to medical school ask her for advice, she wants to shake them and yell "Don't do it!" (But she never does.) How did she get into this fix? In high school she already wanted to be a doctor. And she is so ambitious and determined that she overcame every obstacle along the way — including, unfortunately, not liking it. Now she has a life chosen for her by a high-school kid. When you're young, you're given the impression that you'll get enough information to make each choice before you need to make it. But this is certainly not so with work. When you're deciding what to do, you have to operate on ridiculously incomplete information. Even in college you get little idea what various types of work are like. At best you may have a couple internships, but not all jobs offer internships, and those that do don't teach you much more about the work than being a batboy teaches you about playing baseball. In the design of lives, as in the design of most other things, you get better results if you use flexible media. So unless you're fairly sure what you want to do, your best bet may be to choose a type of work that could turn into either an organic or two-job career. That was probably part of the reason I chose computers. You can be a professor, or make a lot of money, or morph it into any number of other kinds of work. It's also wise, early on, to seek jobs that let you do many different things, so you can learn faster what various kinds of work are like. Conversely, the extreme version of the two-job route is dangerous because it teaches you so little about what you like. If you work hard at being a bond trader for ten years, thinking that you'll quit and write novels when you have enough money, what happens when you quit and then discover that you don't actually like writing novels? Most people would say, I'd take that problem. Give me a million dollars and I'll figure out what to do. But it's harder than it looks. Constraints give your life shape. Remove them and most people have no idea what to do: look at what happens to those who win lotteries or inherit money. Much as everyone thinks they want financial security, the happiest people are not those who have it, but those who like what they do. So a plan that promises freedom at the expense of knowing what to do with it may not be as good as it seems. Whichever route you take, expect a struggle. Finding work you love is very difficult. Most people fail. Even if you succeed, it's rare to be free to work on what you want till your thirties or forties. But if you have the destination in sight you'll be more likely to arrive at it. If you know you can love work, you're in the home stretch, and if you know what work you love, you're practically there. Notes [1] Currently we do the opposite: when we make kids do boring work, like arithmetic drills, instead of admitting frankly that it's boring, we try to disguise it with superficial decorations. [2] One father told me about a related phenomenon: he found himself concealing from his family how much he liked his work. When he wanted to go to work on a saturday, he found it easier to say that it was because he "had to" for some reason, rather than admitting he preferred to work than stay home with them. [3] Something similar happens with suburbs. Parents move to suburbs to raise their kids in a safe environment, but suburbs are so dull and artificial that by the time they're fifteen the kids are convinced the whole world is boring. [4] I'm not saying friends should be the only audience for your work. The more people you can help, the better. But friends should be your compass. [5] Donald Hall said young would-be poets were mistaken to be so obsessed with being published. But you can imagine what it would do for a 24 year old to get a poem published in The New Yorker. Now to people he meets at parties he's a real poet. Actually he's no better or worse than he was before, but to a clueless audience like that, the approval of an official authority makes all the difference. So it's a harder problem than Hall realizes. The reason the young care so much about prestige is that the people they want to impress are not very discerning. [6] This is isomorphic to the principle that you should prevent your beliefs about how things are from being contaminated by how you wish they were. Most people let them mix pretty promiscuously. The continuing popularity of religion is the most visible index of that. [7] A more accurate metaphor would be to say that the graph of jobs is not very well connected. Thanks to Trevor Blackwell, Dan Friedman, Sarah Harlin, Jessica Livingston, Jackie McDonough, Robert Morris, Peter Norvig, David Sloo, and Aaron Swartz for reading drafts of this.
August 20 · 14 min read ·
TechnologyLearn Git
Learn Git Learn the Basics of Git in Under 10 Minutes https://miro.medium.com/v2/resize:fit:1975/1*4kDk9CZEEJBllqd3Fx549A.png Yes, the title is clickbait. There is no way you can understand the basics of git technology in just 10 minutes. But you can get pretty close in about 25 minutes. And that is the purpose of this article. If you want to get started on learning about Git technology, you’ve come to the right place. This is a comprehensive beginner’s guide to Git. There are many clients for Git. The technology is all the same no matter the client. But in this guide, we’ll be using GitHub to understand Git. You can read a Portuguese supplement to the article here. Translations are welcome! Just send me a pull request. Let’s get started! What is Version Control? Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later. So ideally, we can place any file in the computer on version control. Umm… Okay… But Why Tho? Here’s Why: A Version Control System (VCS) allows you to revert files back to a previous state, revert the entire project back to a previous state, review changes made over time, see who last modified something that might be causing a problem, who introduced an issue and when, and more. Using a VCS also means that if you screw things up or lose files, you can generally recover easily. And sometimes you just want to know “who wrote this crap”, and having access to that information is worthwhile 😈. So What is Git? Git is a version-control system for tracking changes in computer files and coordinating work on those files among multiple people. Git is a Distributed Version Control System. So Git does not necessarily rely on a central server to store all the versions of a project’s files. Instead, every user “clones” a copy of a repository (a collection of files) and has the full history of the project on their own hard drive. This clone has all of the metadata of the original while the original itself is stored on a self-hosted server or a third-party hosting service like GitHub. Git helps you keep track of the changes you make to your code. It is basically the history tab for your code editor(With no incognito mode 🌚). If at any point while coding you hit a fatal error and don’t know what’s causing it you can always revert back to the stable state. So it is very helpful for debugging. Or you can simply see what changes you made to your code over time. https://miro.medium.com/v2/resize:fit:630/1*Lp_67l9zwur7aaFAhpVDrg.png A simple example of version history of a file. In the example above, all three cards represent different versions of the same file. We can select which version of the file we want to use at any point in time. So I can jump to and fro to any version of the file in the git time continuum. Git also helps you synchronise code between multiple people. So imagine you and your friend are collaborating on a project. You both are working on the same project files. Now Git takes those changes you and your friend made independently and merges them into 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. And collaborating long-distance becomes as easy as HTML 🙃. Git Workflow: Before we start working with Git commands, it is necessary that you understand what it represents. What is a Repository? A repository a.k.a. repo is nothing but a collection of source code. There are four fundamental elements in the Git Workflow. Working Directory, Staging Area, Local Repository, and Remote Repository. https://miro.medium.com/v2/resize:fit:630/1*iL2J8k4ygQlg3xriKGimbQ.png Diagram of a simple Git Workflow If you consider a file in your Working Directory, it can be in three possible states. It can be staged. This means the files with the updated changes are marked to be committed to the local repository but not yet committed. It can be modified. This means the files with the updated changes are not yet stored in the local repository. It can be committed. This means that the changes you made to your file are safely stored in the local repository. git add is a command used to add a file that is in the working directory to the staging area. git commit is a command used to add all files that are staged to the local repository. git push is a command used to add all committed files in the local repository to the remote repository. So in the remote repository, all files and changes will be visible to anyone with access to the remote repository. git fetch is a command used to get files from the remote repository to the local repository but not into the working directory. git merge is a command used to get the files from the local repository into the working directory. git pull is a command used to get files from the remote repository directly into the working directory. It is equivalent to a git fetch and a git merge . Now that we know what Git is and its basic terminologies, let’s see how we can place a file under git. We’re going to do it the right way and the difficult way. Without any GUI applications. I’m assuming you already have a file you want to place under version control. If not create a sample folder named ‘MuskCult’ and place some sample code files in it. Step 0: Make a GitHub Account. Duh. If you don't already have one, you can make one here. Step 1: Make sure you have Git installed on your machine. If you are on a Mac, fire up the terminal and enter the following command: $git --version This will prompt open an installer if you don’t already have git. So set it up using the installer. If you have git already, it’ll just show you which version of git you have installed. If you are running Linux(deb), enter the following in the terminal: $sudo apt install git-all If you are on Windows: $get a mac Just kidding… Relax… The number of people I triggered… Phew… Go to this link or this link for more info on how to get it. Step 2: Tell Git who you are. Introduce yourself. Slide in. Seriously, mention your Git username and email address, since every Git commit will use this information to identify you as the author. $git config --global user.name "YOUR_USERNAME"$git config --global user.email "im_satoshi@musk.com"$git config --global --list # To check the info you just provided https://miro.medium.com/v2/resize:fit:630/1*JbyUdhLMEdglRxQk6PH7Vg.gif Step 3: Generate/check your machine for existing SSH keys. (Optional) Why you ask? Using the SSH protocol, you can connect and authenticate to remote servers and services. With SSH keys, you can connect to GitHub without supplying your username or password at each visit. Follow this link to learn more about SSH. Go here to check if you have an existing SSH key. Go here to generate a SSH Key. Go here to add the SSH key to your GitHub account. And finally, go here to test its connection. If you did setup SSH, every git command that has a link you replace it by: Instead of : https://github.com/username/reponameYou use : git@github.com/username/reponame.git Note : You can use both ways alternatively I’ll be using SSH protocol in this tutorial. Step 4: Let’s Git Create a new repository on GitHub. Follow this link. Now, locate the folder you want to place under git in your terminal. $ cd Desktop/MuskCult Initialize Git: And to place it under git, enter: $ touch README.md # To create a README file for the repository $git init # Initiates an empty git repository https://miro.medium.com/v2/resize:fit:630/1*Q_DUXRghgFQb9F47mUB6LQ.gif Now go edit the README.md file to provide information about the repository. Add files to the Staging Area for commit: Now to add the files to the git repository for commit: $git add . # Adds all the files in the local repository and stages them for commitOR if you want to add a specific file$git add README.md # To add a specific file Before we commit let’s see what files are staged: $git status# Lists all new or modified files to be committed https://miro.medium.com/v2/resize:fit:630/1*a2_hw7cMe2R9R_aI86dB-A.gif Commit Changes you made to your Git Repo: Now to commit files you added to your git repo: $git commit -m "First commit" # The message in the " " is given so that the other users can read the message and see what changes you made https://miro.medium.com/v2/resize:fit:630/1*LoUwFy29RkgCS7hCajd_3g.gif Uncommit Changes you just made to your Git Repo: Now suppose you just made some error in your code or placed an unwanted file inside the repository, you can unstage the files you just added using: $git reset HEAD~1 # Remove the most recent commit # Commit again! https://miro.medium.com/v2/resize:fit:630/1*rxOX_U-ZRmGfhgIhNWlDIQ.gif Add a remote origin and Push: Now each time you make changes in your files and save it, it won’t be automatically updated on GitHub. All the changes we made in the file are updated in the local repository. Now to update the changes to the master: $git remote add originremote_repository_URL #sets the new remote The git remote command lets you create, view, and delete connections to other repositories. $git remote -v # List the remote connections you have to other repositories. The git remote -v command lists the URLs of the remote connections you have to other repositories. $git push -u origin master# pushes changes to origin Now the git push command pushes the changes in your local repository up to the remote repository you specified as the origin. https://miro.medium.com/v2/resize:fit:630/1*w-nfopsKIks_JRzFe5D8xA.gif And now if we go and check our repository page on GitHub it should look something like this: https://miro.medium.com/v2/resize:fit:630/1*aQljQFkytY84BgmlVtpgmw.png And that’s it. You’ve just added the files to the repository you just created on GitHub. See the Changes you made to your file: Once you start making changes on your files and you save them, the file won’t match the last version that was committed to git. To see the changes you just made: $git diff# To show the files changes not yet staged https://miro.medium.com/v2/resize:fit:630/1*xym1QvvvWorfoyGMXv28Yg.gif Revert back to the last committed version to the Git Repo: Now you can choose to revert back to the last committed version by entering: $git checkout .OR for a specific file$git checkout -- <filename> https://miro.medium.com/v2/resize:fit:630/1*HYgYkfo3W4MUA8CJl12rXg.gif View Commit History: You can use the git log command to see the history of commits you made to your files: $git log https://miro.medium.com/v2/resize:fit:630/1*9w7uBJcQMxc708DBw8Sewg.gif Each time you make changes that you want to be reflected on GitHub, the following are the most common flow of commands: $git add . $ git status# Lists all new or modified files to be committed $git commit -m "Second commit" $git push -u origin master https://miro.medium.com/v2/resize:fit:630/1*rWBJnBdF1V8YO_mi-jEfxA.gif Now if we go and see our repo, we can identify whether the commit was successful by looking at the commit message for each file. https://miro.medium.com/v2/resize:fit:630/1*QHM8m5HGavHkdzPz06UWGw.png Step 5: That’s all well and good… But How do I download and work on other repositories on GitHub? Cloning a Git Repo: Locate to the directory you want to clone the repo. Copy the link of the repository you want and enter the following: $ git cloneremote_repository_URL Feel free to go ahead and clone the repo I created above using: https://github.com/Gothamv/MuskCult https://miro.medium.com/v2/resize:fit:630/1*6NACk8-IiBjbauM-k-aesQ.gif Pushing Changes to the Git Repo: Now you can work on the files you want and commit to changes locally. If you want to push changes to that repository you either have to be added as a collaborator for the repository or you have created something known as a pull request. Go and check out how to do one here and give me a pull request with your code file. Collaborating: So imagine you and your friend are collaborating on a project. You both are working on the same project files. Each time you make some changes and push it into the master repo, your friend has to pull the changes that you pushed into the git repo. Meaning to make sure you’re working on the latest version of the git repo each time you start working, a git pull command is the way to go. Now below is an example of a project my friend and I are collaborating on: https://miro.medium.com/v2/resize:fit:630/1*2-tl2rHsgPqiv88aI55CPw.png There has just been a commit on the repo So to make sure those changes are reflected on my local copy of the repo: $git pull origin master https://miro.medium.com/v2/resize:fit:630/1*ySDKu2OEdkc26yOUp-TJJQ.gif Here are two more useful git commands: $git fetch AND $git merge In the simplest terms, git fetch followed by a git merge equals a git pull. But then why do these exist? When you use git pull, Git tries to automatically do your work for you. It is context-sensitive, so Git will merge any pulled commits into the branch you are currently working in. git pull automatically merges the commits without letting you review them first. When you git fetch, Git gathers any commits from the target branch that do not exist in your current branch and stores them in your local repository. However, it does not merge them with your current branch. This is particularly useful if you need to keep your repository up to date, but are working on something that might break if you update your files. To integrate the commits into your master branch, you use git merge. One More Thing: .gitignore So what is it? .gitignore tells git which files (or patterns) it should ignore. It's usually used to avoid committing transient files from your working directory that aren't useful to other collaborators, such as compilation products, temporary files IDEs create, etc. https://miro.medium.com/v2/resize:fit:630/1*3NFtOjfz0NvNSwba7YCmDA.png So in the above example, files like pycache, .DS_Store are used by the system to store information for faster access. This is not useful for other collaborators. So we can tell git to ignore them by adding a .gitignore file. Use the touch command to create the .gitignore file: $ touch .gitignore And you can add the following patterns to tell git to ignore such files. /*.cmake /*.DS_Store /.user /build etc. depending upon the files you want git to untrack And that’s pretty much it for the basics. Stay tuned for Part 2 which will focus on Branch, Merge, Stash, Rebase, etc. Peace Out ✌️
August 20 · 4 min read ·
Technology301K
Stories
16K
Writers
Au Chang
I love observing and writing
Au Chang
I love observing and writing
Au Chang
I love observing and writing