Git commands Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What is the routine you should do when commiting changes to the code?

A

git add , (adds files to the staging area)
git commit -m ‘message’ (takes a snapshot of the repository)
git commit -am ‘message’ (shortcut to add files and commit changes)
git pull (pulls any changes from remote repository to local computer)
git push (pushes any local changes (commits to a remote server)

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

What do you need to do with merge conflicts?

A

If the same line was edited in different versions, it may result in merge confilict. Git by default will try to resolve it automatically, however sometimes it might require human action.

In such a case, locally you need to delete the lines that are not wanted (git provides support in those places) and push the results (this version will be marked as ‘the correct one’

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

What are the commands that support branching in git?

A

‘Branching’ is a feature of Git that allows a project to move in multiple different directions simultaneously. There is one master branch that is always usable, but any number of new branches can be created to develop new features.

git branch (lists all the branches currently in a repository)
git branch  (creates a new branch called feature)
git checkout  (switch working branch (move the HEAD) to feature branch.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you merge branches?

A

Go to the master branch.
git checkout master
Type git merge (to merge a feature branch)

In case a message appears: Please enter a commit message to explain why this merge is necessary, especially if it merges an updated upstream into a topic branch

press 'i' (for insert)
writhe message
press esc
write ':wq' for (write and quit)
then press enter

After I am done with the branch i can
git branch -d

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

How can we break down git pull?

A

Git pull fetches the origin/master.

And merges it with local master, so we are exactly at the same spot.

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

How do you checkout to a commit?

A

git checkout SHA
the repository will most likely become have a DETACHED HEAD.
In order to fix that, we need to create a branch and checkout to it, then the changes could be commited.

git branch sample
git checkout sample

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

Deleting a branch

A

git branch -d branch_name

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

“How do I delete file from Github?”

A

git rm -r

alias gri=”git ls-files –ignored –exclude-standard | xargs -0 git rm -r”

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

How to revert a git repository to a previous commit?

A

git revert –no-commit 0766c053..HEAD
git commit

The –no-commit flag lets git revert all the commits at once- otherwise you’ll be prompted for a message for each commit in the range, littering your history with unnecessary new commits.)

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

How can you refresh a repository after changing line endings

A

When you set the core.autocrlf option or commit a .gitattributes file, you may find that Git reports changes to files that you have not modified. Git has changed line endings to match your new configuration.

$ git add . -u
$ git commit -m “Saving files before refreshing line endings”
$ git rm –cached -r . # Remove every file from Git’s index.
$ git reset –hard # Rewrite the Git index to pick up all the new line endings.
$ git add . # Add all your changed files back, and prepare them for a commit.
$ git commit -m “Normalize all the line endings” # Commit the changes to your repository.

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