5.2 Given a scenario, carry out version control using Git Flashcards

1
Q

What is the clone command used for?

A

The git clone command creates a local repository from the contents of a remote repository. The argument provided is the location of the remote repository

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the push command used for?

A

To have changes from the local repository sent to the remote repository, use the git push command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the pull command used for?

A

If changes have been made to remote repository and you want to download these changes into the local repository, use the git pull command:

$ git pull origin master

origin refers to the remote repository, while master refers to the branch that should be updated

The git pull command will attempt to merge changes into existing files. If this can’t be handled automatically, you may have to perform a manual merge operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the commit command used for?

A

To have changes made to the working directory placed in the local repository, you first have to add it to the staging area and then you need to commit it to the repository, like so:

$ git add first.sh
$ git commit -m "added first.sh"
[master 3b36054] added first.sh
 1 file changed, 5 insertions(+)
 create mode 100644 first.sh

The git add command will place the file in the staging area. The git commit command will take all of the new files in the staging area and commit them to the local repository. The -m option is used to add a message (in this case, the reason for the commit was given)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the merge command used for?

A

Suppose you create a new branch to add a new feature to a file. After testing out this new feature, you are ready to implement it in the master branch. To do this, you will need to merge the content from the new branch (feature127 branch in the following example) into the master branch. Start by committing all changes in the feature127 branch and then switch back to the master branch

$ git commit -a -m “feature added to showmine.sh”
[feature127 2e5defa] feature added to showmine.sh
1 file changed, 5 insertions(+), 2 deletions(-)
$ git checkout master
Switched to branch ‘master’
Your branch is ahead of ‘origin/master’ by 3 commits.
(use “git push” to publish your local commits)

You must be in the branch that you want to merge into in order to correctly run the next command. The following git merge command will merge the changes from the feature127 branch into the master branch:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a branch?

A

When you first create a project, the code is associated with a branch called “master.” If you want to create a new branch, execute the git branch command:

$ git branch test
This doesn’t mean you are suddenly working in the new branch. As you can see from the output of the git status command, the git branch command doesn’t change your current branch:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you switch to a new branch?

A

To switch to the new branch, execute the git checkout command:

$ git checkout test
Switched to branch ‘test’

Note

You can create a branch and switch to it by using the -b option to the git checkout command: git checkout -b test.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you see changes made on different branches?

A

You can see the changes made on different branches, along with the comments you provided for each change, by using the git log command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you create a new repository in the current local directory?

A

To create a new repository in the current local directory, use the git init command:

$ git init test
Initialized empty Git repository in /tmp/test/.git/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the git config command used for?

A

The git config command is used to configure the git utility.

$ git config –global user.name “Bo Rothwell”
$ git config –global user.email bo@onecoursesource.com
The –global option results in configuration options being stored in a configuration file in the user’s home directory, as shown here:

$ more ~/.gitconfig
[user]
name = Bo Rothwell
email = bo@onecoursesource.com

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the .gitignore file used for?

A

To have git commands ignore a file, create a file named .gitignore in the working directory and place the filename to ignore inside of this file

Note

You can also use wildcard characters (*, ?, and [range]) in the .gitignore file to match a collection of files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the .git/ purpose?

A

Local repository data is stored under the .git directory under the directory the git command created. For example, consider the following command:

git init test
Initialized empty Git repository in /tmp/test/.git/

This command was executed in the /tmp directory and created a local repository directory of /tmp/test. The repository data is actually stored in the /tmp/test/.git directory:

The .git directory should not be modified directly. This directory contains a collection of databases that contain all the files and versions for the git repository.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly