Learn Git - Init, Status, Add, Commit

Question Click to View Answer

How do you start Git and what is the process called?

$ git init

The process is called initializing a git repository

How do you determine the current state of the project?

$ git status

Move all your changes since your last commit to the staging area.

$ git add .

Store the saved changes in the repository and add a message "first commit".

$ git commit -m "first commit"

Show a list of all the commits that have been made.

$ git log

How do you put your local repository (repo) on the GitHub server?

a. create a new repository in github

b. get the SSH key (SSH stands for secure shell)

c. $ git remote add origin [SSH key - something like git@github.com…]

d. $ git push -u origin master

Take a git project from GitHub to your local machine to work on it.

$ git pull origin master

Or, if you are taking a project that is not already on your local machine, use $ git clone.

What is the purpose of working off multiple branches.

You can create a separate branch when you are developing a feature, etc. and can commit to this branch separately. When the feature branch is working properly, you can merge it with the master branch.

Create a branch called working

$ git checkout -b working

List all of the branches.

$ git branch

Switch to the working branch

$ git checkout working

Merge the changes that were made in the working branch with the master branch.

$ git checkout master
$ git merge working

Delete the working branch

$ git branch -d working

Put everything up on the remote repository.

$ git push

Pull a branch from a remote repository and create the branch locally

git checkout -b fix_stuff origin/fix_stuff