Skip to content
This repository has been archived by the owner on Feb 4, 2020. It is now read-only.

gitBasics

Shaan Menon edited this page Oct 22, 2015 · 8 revisions

#git Tutorial Page


Go Back to Home Page

Git Branch and Git Merge

This Page is to help you understand the basics of git.

Download git here


git init


git init

This command allows you to initialize git into the following folder on your computer locally. all sub folder created in this branch afterwords will also be automatically initiallized with git. This allows you to use all of the following git commands.

git clone


Here is a sample to follow:

$ git clone https://github.com/team/projectname.git

so for me cloning this project it would be:

$ git clone https://github.com/RowanACM/ACM-Website.git

git clone creates a local version of the repository on to your machine. This way you are able to edit, insert, and delete files locally to try things without actually impacting the project. This lets everyone work on the project without interfering with everyone else.

git pull


$ git pull repository local

so for me executing a pull command would be:

$ git pull origin master

origin refers to the repository you are requesting from and master is the local place that you want it updated to. Origin and master are keywords to git initialized in your config file in the .git folder. Origin is the repository location, and master is the location the local version is stored on your computer.

This git command makes your local copy up to date with the origin repository. It will update and add and remove all files necessary to and from your local machine. with newer versions of git specifying origin and master may be unnecessary, so you would only need to say:

$ git pull

There is a common flag used when updating your local workspace with repository code after you have made changes in your workspace that you want to keep. That is:

$ git pull --rebase

This tells git to pull the files from the repository and then lay all of you changes on top of it. This is helpful because in order to update your changes onto the reposiory your local workspace must be completely upto date for everything that you are not changing. This is commonly run before making a push or merging.

git add


Here is a sample to follow:

$ git add filename

so for me adding this file to the project it would be:

$ git add gitBasics.md

The git add command tells git that you know that you have changed certain files, and you are going to sync them with the repository. If you dont add every file that you have changed git will not allow you to proceed at later steps.

Note: you can add more than one file at a time with git add you just need to seperate each filename with a space

git commit


Here is a sample to follow:

$ git commit -m "Commit Message Here"

so for me commiting this file to the project it would be:

$ git commit -m "adding git tutorial page"

This git command is basically saying that i want my previously added files from git add to be merged with the repository. The -m flag says that i am including a message with my commit. We recomend that you use the -m flag and write a short message on what you did because it helps everyone keep track of why things were modified in the project.

git push


Here is the command:

$ git push

This tells git to update the repository with all of your commited changes in your local version. This command will not push if your local version is not up to date minus the changes to files added with git add.

git diff


Here is the command:

$ git diff 

This command allows you to check the changes you have made between what is on the repository and what is in your local working directory. You can check only certain files by writing the filename after diff on the command like so:

$ git diff filename

This allows you to see what you have removed or added to the file and lets you make sure that the changes that you have made are the ones that you want to make. If nothing has changed in the file or entire working directory if you dont put a filename then nothing will be displayed in the command line.

Clone this wiki locally