GIT Flashcards

1
Q

Reset to head

A

git reset –hard origin/master

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

__ works by transferring each local commit to the updated main branch one at a time. This means that you catch merge conflicts on a __ basis rather than resolving all of them in one massive merge commit. This keeps your commits as focused as possible and makes for a clean project history. In turn, this makes it much easier to figure out where bugs were introduced and, if necessary, to roll back changes with minimal impact on the project.

A

Rebasing works by transferring each local commit to the updated main branch one at a time. This means that you catch merge conflicts on a commit-by-commit basis rather than resolving all of them in one massive merge commit. This keeps your commits as focused as possible and makes for a clean project history. In turn, this makes it much easier to figure out where bugs were introduced and, if necessary, to roll back changes with minimal impact on the project.

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

Make changes and commit

A
git status # View the state of the repo
git add <some-file> # Stage a file
git commit # Commit a file</some-file>

Remember that since these commands create local commits

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

Push new commits to central repository

A
git push origin main
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

List all brances

A
  • Local: git branch
  • Remote: git branch -a
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Create a new branch called <branch>.

A

git branch <branch>
Note that this only creates the new branch. To start adding commits to it, you need to select it with git checkout, and then use the standard git add and git commit commands.

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

Delete the specified branch

A

git branch -d <branch>

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

Create a remote branch

A

$ git remote add new-remote-repo https://bitbucket.com/user/repo.git
//Add remote repo to local repo config
$ git push <new-remote-repo> crazy-experiment
//pushes the crazy-experiment branch to new-remote-repo

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

Viewing git remote configurations

A

git remote -v

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

How to do interactive rebasing

A

To begin an interactive rebasing session, pass the i option to the git rebase command:

git checkout feature
git rebase -i main

This will open a text editor listing all of the commits that are about to be moved:

pick 33d5b7a Message for commit #1
pick 9480b3d Message for commit #2
pick 5c67e61 Message for commit #3

This listing defines exactly what the branch will look like after the rebase is performed. By changing the pick command and/or re-ordering the entries, you can make the branch’s history look like whatever you want. For example, if the 2nd commit fixes a small problem in the 1st commit, you can condense them into a single commit with the fixup command:

pick 33d5b7a Message for commit #1
fixup 9480b3d Message for commit #2
pick 5c67e61 Message for commit #3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Fix up the last few commits

A

fix up the last few commits. For example, the following command begins an interactive rebase of only the last 3 commits.

git checkout feature 
git rebase -i HEAD~3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

it’s usually a good idea to clean up your code with an __ before submitting your pull request.

A

it’s usually a good idea to clean up your code with an interactive rebase before submitting your pull request.

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

Integrating an approved feature

A

git checkout feature
git rebase -i main
//[Clean up the history]
git checkout main
git merge feature

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

Lists all the remote branches.

A

git branch -a

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

What are the options for interactive rebasing?

– is the default action. In this case it would reapply the commit as is, no changes in its contents or message.
– in a commit I can change the comment:
–, which melds the commit into the previous one (the one in the line before)
–, which acts like “squash”, but discards this commit’s message

A

pick (p for short) is the default action. In this case it would reapply the commit as is, no changes in its contents or message.
reword (r for short) in a commit I can change the comment:
squash (s for short), which melds the commit into the previous one (the one in the line before)
fixup (f for short), which acts like “squash”, but discards this commit’s message

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

How to make git forget about a tracked file?

A

To stop tracking a file, we must remove it from the index:

git rm --cached <file>
To remove a folder and all files in the folder recursively:

git rm -r --cached <folder>