git commands Flashcards
How would you clone https://github.com/libgit2/libgit into the current directory
git clone https://github.com/libgit2/libgit
How would you create a snapshot of the current state of all the tracked files in the repository.
git commit
How would you create a new branch named bugFix that points to current HEAD?
git branch bugFix
How would you create a new branch named bugFix that points to current HEAD? And update HEAD to point to bugFix?
git checkout -b bugFix
How would you create a new branch named bugFix that points to the commit at hash c0s0cv0s ?
git branch bugFIx c0s0cv0s
How would you create a new branch named bugFix at the grandparent of Head?
git branch bugFix HEAD~2
You are on main branch. bugFix has been updated in parallel with main. How would you create a new commit that has the change of both main and bugFix?
git merge bugFix;
What kind of merge is it if the HEAD is an ancestor of the branch you merge with?
Fast Forward
What command takes a set of commits that are not the ancestor of the current branch and brings them in to be ANCESTORS of the latest commit on the current branch. (Example: you want to get recent changes from main to be ancestors of bugFix.)
git checkout bugfix; git rebase main
If you don’t like the changes in the last commit, how could you create a new commit that does not include those changes?
git revert HEAD
How would you copy a series of specific commits (hashes 1234567 and 2345678) to be below your HEAD (current location), AND move the current branch and head pointers to last commit copied.
git cherry-pick 1234567 2345678
What command would open up an editor that would allow you to interactively move around the last 4 commits on your current branch?
git rebase -i HEAD~4
How would you permanently mark commit 3456789 with the label version1?
git tag version1 3456789
How would you get from the remote main, deltas for changes on main, without actually updating the files that display on the local filesystem?
git fetch
What command would create a new branch namedmyBranchand sets it to trackorigin/main and makes myBranch the current branch?
git checkout -b myBranch origin/main
What kind of branch do you set up on your local so that, if yoy do a pull, you will get updates from the remote branch. And if you do a push, updates on the local will be uploaded to the branch it is tracking?
tracking branch
How would you create a new branch bugFix, pointing to where HEAD currently points?
git branch bugFix
What command shows all the branches and shows where HEAD points?
git branch
How do you commit with the comment “I fixed a bug”?
git commit -m “I fixed a bug”
How do you show changes for files that are tracked?
git diff
How would you get any changes and new files from work area to staging area?
git add .
How would you see changes you are about to commit?
git diff –staged
How would you see a history of commits?
git log