In this case however, the changes are in different parts of the file, so git can automatically figure out what the file should look like. You and Isabelle have both made changes in the same file, which can make git a little confused. Oops, what's this? Suddenly your editor pops up. You will need to pull those changes first, using git pull. What happens? You can't, since there are new changes in the remote repository. Meanwhile, you start adding some printing functionality. Isabelle > git commit -am "Add favorite movie" She adds your favorite movie, commits and pushes. isabelle (create a folder somewhere outside the repo) We're gonna pretend to be Isabelle now, by cloning the repo again in a different folder. Your childhood friend Isabelle knows everything about you so she can add things too. Introducing the NPCĪctually, this would be easier with some help. animal = 'cat'Ĭheck the diff, commit and push. Just don't go off the trail since we are doing this to stage some git situations. Let's expand main.py by adding some of your favorite things! I'll be writing mine in the examples but feel free to write whatever you want. We're going to stage some situations that happen as you collaborate, and practice dealing with them. Those are the basics! Do git push and continue on. Mutliple flags can be combined, so an equvialent command is > git commit -am "Add call to print_favorites" > git commit -a -m "Add call to print_favorites" We could do git add again to stage it, but for files in this category it's enough to add the -a (for all) flag to the commit command to have them all staged and commited. This time main.py is not under "untracked files" but under "tracked files not staged for commit". You can also use `git commit -v` (for verbose) to see this output while writing your commit message. I often find sneaky debug prints that I forgot to remove this way. Try that now and make sure you are only committing the new funticon call. With git status you can check what files are being commited, but to see what lines of code are being commited you can use git diff. You can now run this using > python main.py (if you happen to have Python, otherwise it's not really important.) git diffĪn important thing to do before committing is to check what's being commited. Add a call to print_favorites: def print_favorites(): We added a function, but we're not calling it yet. To send the commit to GitHub, making it backed up and available anywhere, we use git push. Our changes are now saved, but only locally. Always remember to write descriptive commit messages! I may or may not follow that advice during this tutorial. Otherwise, a good convention is writing multiple-lined commit messages, where the first line stands on its own and the following lines expand on the contents of the commit. It will be very useful during this tutorial. This is nice if you want to write short messages for small changes, maybe in your private repo. So I would write > git commit -m "Add a print function" When committing, I like to use the flag -m (for message) to write a commit message directly on the command line. Let's add some content to main.py, def print_favorites(): You can now check git status again and see that everything is commited. Write something like "Add main.py", save it and exit. This will open your text editor and allow you to type a commit message. Main.py is now ready to be commited! Type > git commit To start tracking the file, we type > git add main.py This basically means that the repo doesn't know and doesn't care about this file at the moment. Let's take a look at the status of the repo using > git status Begin by creating an empty file called main.py. Start by setting up a repo and cloning it to your computer. I'd recommend going though this tutorial for a good overview of what can be done, and then reading up on the more confusing things after. Thus, this tutorial mostly explains how, not why. I try to not explain too much about what's going on behind the scenes, since I think the reason a lot of people don't use many of git's functions is that they're all hidden inside pages and pages of backstory in tutorials or documentation. Make sure to read the instructions so you don't miss anything. You don't need any previous python experience to follow, in fact this might even teach you some basic (probably bad) python. During the course of this adventure you will create a small, rather useless python program. This tutorial assumes you have installed git on your computer, and preferably tried it out a little. Welcome to the git adventure! It is time for you to embark on your journey through the many wonders of git. Git Gud Git Guide Intermediate level git tutorial
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |