









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










You will learn in this tutorial: Git and GitHub Remote and local in Git Branches How to make changes and get changes from a repository Get started with GitHub desktop a GUI enviroment for GitHub New to git? Follow the steps below to get comfortable making changes to the code base, opening up a pull request (PR), and merging code into the primary branch. Any important git and GitHub terms are in bold with links to the official git reference materials. Step 0: Install git and create a GitHub account The first two things you'll want to do are install git and create a free GitHub account. Softwared needed: Git - Downloads (git-scm.com) GitHub Desktop | Simple collaboration from your desktop Git and GitHub A quick aside: git and GitHub are not the same thing. Git is an open-source, version control tool created in 2005 by developers working on the Linux operating system; GitHub is a company founded in 2008 that makes tools which integrate with git. You do not need GitHub to use git, but you cannot use GitHub without using git. There are many other alternatives to GitHub, such as GitLab, BitBucket, and “host-your-own” solutions such as gogs
and gittea. All of these are referred to in git-speak as “remotes”, and all are completely optional. You do not need to use a remote to use git, but it will make sharing your code with others easier. Step 1: Create a local git repository When creating a new project on your local machine using git, you'll first create a new repository (or often, 'repo', for short). To use git we'll be using the terminal. If you don't have much experience with the terminal and basic commands, check out this tutorial (If you don’t want/ need a short history lesson, skip to step three.) To begin, open up a terminal and move to where you want to place the project on your local machine using the cd (change directory) command. For example, if you have a 'projects' folder on your desktop, you'd do something like: Open command propt and create a new folder MyFirstRepo Copy a file into this folder. In this tutorial a file name Mongoose 101.docx has been added To initialize a git repository in the root of the folder, run the git init command: Notice: dir /b -> to view the content of current directory
2, when you make changes to your repo, git notices that a file has changed but won't do anything with it (like adding it in a commit). To add a file to a commit, you first need to add it to the staging environment. To do this, you can use the git add
Run the command git commit -m "Your message about the commit" The message at the end of the commit should be something related to what the commit contains - maybe it's a new feature, maybe it's a bug fix, maybe it's just fixing a typo. Don't put a message like "asdfadsf" or "foobar". That makes the other people who see your commit sad. Very, very, sad. Commits live forever in a repository (technically you can delete them if you really, really need to but it’s messy), so if you leave a clear explanation of your changes it can be extremely helpful for future programmers (perhaps future you!) who are trying to figure out why some change was made years later. Step 5: Create a new branch Now that you've made a new commit, let's try something a little more advanced. Say you want to make a new feature but are worried about making changes to the main project while developing the feature. This is where git branches come in. Branches allow you to move back and forth between 'states' of a project. Official git docs describe branches this way: ‘A branch in Git is simply a lightweight movable pointer to one of these commits.’ For instance, if you want to add a new page to your website you can create a new branch just for that page without affecting the main part of the project. Once you're done with the page, you can merge your changes from your branch into the primary branch. When you create a new branch, Git keeps track of which commit your branch 'branched' off of, so it knows the history behind all the files. Let's say you are on the primary branch and want to create a new branch to develop your web page. Here's what you'll do: Run git checkout -b
Step 6: Create a new repository on GitHub If you only want to keep track of your code locally, you don't need to use GitHub. But if you want to work with a team, you can use GitHub to collaboratively modify the project's code. To create a new repo on GitHub, log in and go to the GitHub home page. You can find the “New repository” option under the “+” sign next to your profile picture, in the top right corner of the navbar: After clicking the button, GitHub will ask you to name your repo and provide a brief description:
When you're done filling out the information, press the 'Create repository' button to make your new repo. GitHub will ask if you want to create a new repo from scratch or if you want to add a repo you have created locally. In this case, since we've already created a new repo locally, we want to push that onto GitHub so follow the '....or push an existing repository from the command line' section: Run the commands which Github gives you
Add changes Commit changes(Security.pdf) to the new branch Push changes to remote Now there will be to branches with diffirent content
Step 8: Create a pull request (PR) A pull request (or PR) is a way to alert a repo's owners that you want to make some changes to their code. It allows them to review the code and make sure it looks good before putting your changes on the primary branch. This is what the PR page looks like before you've submitted it: And this is what it looks like once you've submitted the PR request:
When you're done, I recommend deleting your branch (too many branches can become messy), so hit that grey 'Delete branch' button as well. You can double check that your commits were merged by clicking on the 'Commits' link on the first page of your new repo. This will show you a list of all the commits in that branch. You can see the one I just merged right up top (Merge pull request #1).
You can also see the hash code of the commit on the right hand side. A hash code is a unique identifier for that specific commit. It's useful for referring to specific commits and when undoing changes (use the git revert