Git 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

git push origin <branch_name>

Pushes a local branch to the origin remote.

git clone remote_location clone_name

Creates a local copy of a remote.

git init

Creates a new git project init means initialize. The command sets up all the tools Git needs to begin tracking changes made to the project.

git remote -v

Lists a Git project's remotes.

If you need to `cd` back to the remote use -->

$ cd ../name-of-remote

git pull command is actually a combination of two other commands :

git fetch followed by git merge

The output below is typical of which command? commit bda95786432d142bbff996ad32045fa4f32ec619 Author: codecademy <[email protected]> Date: on Nov 16 13:13:33 2015 -0500 First commit

git log

What Git command gives the output below? Unstaged changes after reset: M file.txt

git reset HEAD file.txt

Which command removes file changes from the staging area?

git reset HEAD filename

The workflow for Git collaborations typically follows this order:

1) Fetch and merge changes from the remote 2)Create a branch to work on a new project feature 3)Develop the feature on your branch and commit your work 4)Fetch and merge from the remote again (in case new commits were made while you were working) 5)Push your branch up to the remote for review

a basic git workflow :

1) modify file & save 2) move the file to the staging area with : `git add filename` 3) make a commit & add a message in present tense : `git commit -m "add hot dog no mustard"`

git checkout HEAD filename

: Discards changes in the working directory.

git reset commit_SHA

: Resets to a previous commit in your commit history.

git reset HEAD filename

: Unstages file changes in the staging area.

What is returned from a `git log`

A 40-character code, called a SHA, that uniquely identifies the commit. This appears in orange text. The commit author (you!) The date and time of the commit The commit message

What is a remote?

A Git repository that allows multiple collaborators to work on the same Git project

git commit

A commit is the last step in our Git workflow. A commit permanently stores changes from the staging area inside the repository.

<<<<<<< HEAD - Intuitive and easy to use, providing crucial functionality ======= - Intuitive and fun for use, offering the best in software >>>>>>> feature

A merge conflict

remote

A remote is a Git repository that lives outside your Git project folder. Remotes can live on the web, on a shared network or even in a separate folder on your local computer.

git fetch

An easy way to see if changes have been made to the remote and bring the changes down to your local copy This command will not merge changes from the remote into your local repository. It brings those changes onto what's called a remote branch.

git log

Commits are stored chronologically in the repository and can be viewed with `git log`

Difference between `merge` & `rebase`?

Merge is always a forward moving change record. Alternatively, rebase has powerful history rewriting features.

After cloning a remote, what is the next step in the Git collaborative workflow?

Fetch from the remote and merge into the local "master" branch

The command "git fetch" does what?

Fetches new commits from the remote, but does not merge them

git fetch

Fetches work from the remote into the local copy.

git remote -v Notice the output: origin /home/ccuser/workspace/curriculum/science-quizzes (fetch) origin /home/ccuser/workspace/curriculum/science-quizzes (push)

Git lists the name of the remote, origin, as well as its location. Git automatically names this remote origin, because it refers to the remote repository of origin. However, it is possible to safely change its name. The remote is listed twice: once for (fetch) and once for (push). We'll learn about these later in the lesson.

git reset 844d1f7

HEAD will be reset to the commit whose SHA starts with 844d1f7

Lets say there are 5 commits sitting next to each other chronologically. 1, 2, 3, 4, 5. The most recent commit is 5. What happens to the commits if we reset back to commit 3 using `git reset commit_SHA`?

HEAD will now be checked out on 3. Commits 4 & 5 will no longer be part of the project.

HEAD

In Git, the commit you are currently on is known as the HEAD commit. In many cases, the most recently made commit is the HEAD commit.

git clone remote_location clone_name

In this command: remote_location tells Git where to go to find the remote. This could be a web address, or a filepath, such as: `/Users/teachers/Documents/some-remote` clone_name is the name you give to the directory in which Git will clone the repository.

Merging a branch into "master"

Integrates changes made on the new branch into "master"

git merge origin/master

Merges `origin/master` into your local branch.

After using `git reset HEAD filename` M scene-2.txt

Notice in the output, "Unstaged changes after reset": M scene-2.txt M is short for "modification"

git reset commit_SHA i.e. `git reset 5d69206`

Sets HEAD to the previous commit This command works by using the first 7 characters of the SHA of a previous commit.

Git Collaborative Workflow

The Git Collaborative Workflow are steps that enable smooth project development when multiple collaborators are working on the same Git project.

merge conflicts in a file : <<<<<<< HEAD happy little land sharks ============== silly little diggers >>>>>>> edits

The contents after the first marker originate from your current working branch `HEAD` After the angle brackets, Git tells us where (from which branch) the changes came from. A line with "=======" separates the two conflicting changes.

What piece is missing from the command? git push origin

The name of the branch you wish to push up to the remote

When you are on "master" and create a new branch

The new branch and "master" share the exact same commit history

git show HEAD

The output of this command will display everything the git log command displays for the HEAD commit, plus all the file changes that were committed.

Where in Git do you create, edit, delete and organize project files?

The working directory

Which is a common reason Git users make a new branch?

To develop a new project feature

Why use the command below? git checkout HEAD filename

To restore a file in the working directory to look as it did in your last commit

The command "git status" shows

Untracked files and file changes staged for commit

untracked files

Untracked means that Git sees the file but has not started tracking changes yet.

We should still learn about rewriting git history checkout : https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud

We should still learn about rewriting git history checkout : https://www.atlassian.com/git/tutorials/learn-git-with-bitbucket-cloud

git add filename_1 filename_2

add multiple files to the staging area

git add filename

adds a file to the staging area. allows git to start tracking a file.

git add .

adds all file in the CWD to the staging area

A branch originates from a commit. `rebase` will take the base of that branch

and rebase it on another commit. Thus rewriting history.

every commit master branch has...

branch will have too. Note that when we commit to branch this does not affect master.

git checkout branch_name

change branches

git diff filename

check the differences between the working directory and the staging area when a file is being tracked.

git status

check the status of the working directory

git branch new_branch

create a new branch

git branch -d branch_name

delete a branch

git checkout -- filename

does the same exact thing that `git checkout HEAD filename` does.

git pull command is used to...

fetch and download content from a remote repository and immediately update the local repository to match that content.

Lists all a Git project's branches.

git branch

Deletes the branch specified.

git branch -d branch_name

Creates a new branch.

git branch branch_name

You accidentally deleted lines from a file. Which command can undo your mistake?

git checkout HEAD filename

Used to switch from one branch to another.

git checkout branch_name

Used to join file changes from one branch to another.

git merge branch_name make sure you are checked out on master

Which command merges the remote "origin" into the local "master" branch?

git merge origin/master

The output below is typical of which command? origin /home/ccuser/workspace/curriculum/science-quizzes (fetch) origin /home/ccuser/workspace/curriculum/science-quizzes (push)

git remote -v

One thing that Git does behind the scenes when you clone is

give the remote address the name `origin`, so that you can refer to it more conveniently.

We create branches to work on a project feature but at the end of the day we want to...

merge branches to master and delete merged branches.

git merge branch_name

merges changes made to branch and adds them to master.

git remote -v

see a list of a Git project's remotes with the command

git branch

tells you which branch you are on. In the output, the * (asterisk) is showing you what branch you're on.

git reset HEAD filename

unstage a file from the staging area. This command resets the file in the staging area to be the same as the HEAD commit. It does not discard file changes from the working directory, it just removes them from the staging area.

git branch -D branchname

use capital -D to delete unmerged branches

git commit -m "this is a message"

use option `-m` to add a message to a commit. must be in quotes & present tense

Repository:

where Git permanently stores those changes as different versions of the project

Working Directory:

where you'll be doing all the work: creating, editing, deleting and organizing files

Staging Area:

where you'll list changes you make to the working directory

git push origin your_branch_name

will push your branch up to the remote, origin.

git checkout HEAD filename

will restore the file in your working directory to look exactly as it did when you last made a commit.


Conjuntos de estudio relacionados

Ch 58: Professional Roles and Leadership

View Set

FINAL (Includes Unit 3 - Chapters 24, 65-68)

View Set

General Behavioral Health Course Objectives, Diagnosis: Behavioral Health PA 604

View Set

Evolve: School-Age Childern (Lvl 3)

View Set