GIT Flashcards
Reset to head
git reset –hard origin/master
__ 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.
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.
Make changes and commit
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
Push new commits to central repository
git push origin main
List all brances
- Local: git branch
- Remote: git branch -a
Create a new branch called <branch>.
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.
Delete the specified branch
git branch -d <branch>
Create a remote branch
$ 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
Viewing git remote configurations
git remote -v
How to do interactive rebasing
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
Fix up the last few commits
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
it’s usually a good idea to clean up your code with an __ before submitting your pull request.
it’s usually a good idea to clean up your code with an interactive rebase before submitting your pull request.
Integrating an approved feature
git checkout feature
git rebase -i main
//[Clean up the history]
git checkout main
git merge feature
Lists all the remote branches.
git branch -a
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
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