1) Can you describe the four different areas ?
Local Working Directory -
Staging Area -
Local Repository -
Remote Repository -
2) Can you describe the three different states for files in the Local Working Directory ?
Untracked files -
Tracked, Unmodified -
Tracked, Modified -
3) What is the difference between a 'remote branch' and a 'local branch' ?
A remote branch represents the version that is on the server
A local branch represents the version that is saved locally
4) What does the 'git clone' command do ?
A new folder is created which is the same name as the repository
All the files are pulled down from the remote repository
Creates a '.git' sub folder
A remote called "origin" is created referencing the URL
A local branch called 'master' is created ??
If no explicit branch is given then the repository 'default branch' will be pulled.
The local branch 'master' is also a tracking branch that tracks 'origin/master'
git clone ""paste the URL""
git clone -b mybranch ""paste the URL""
5) Write code to get all the latest changes (into an empty folder)
git remote add <remote_name> <paste the URL from the clone button in the UI>
git pull remote_name branch_name
git pull remote_name master
6) Write code to get all the latest changes (overwrite local changes)
git fetch remote_name branch_name
git reset --hard // reset to the last commit
git reset --hard <last commit>
7) Write code to check-in your latest changes ?
git add --all
git commit -m "my comment" //the m switch allows you to add a comment
git push origin branch_one
8) Write code to switch to a different branch ?
git checkout master
git checkout feature/branch_one
9) Write code that displays all the local and remote branches ?
git branch --all
git branch //only local branches
git branch --remote //only remote branches
10) Write code to delete a local branch ?
git branch --delete local_branch_name
If the branch is not fully merged you need to run
git branch -D local_branch_name
11) Write code to delete a remote branch ?
git push origin --delete feature/oldfeature
If you delete a remote branch, the corresponding local branch is removed automatically.
12) Write code to delete a folder recursively ?
git rm -r foldername
13) What is a 'tracking branch' ?
A tracking branch is a local branch that automatically tracks and refreshes when changes are made on the remote branch.
In this context the remote branch is called an upstream branch.
14) What is the HEAD ?
This is a label that refers to the currently active head in your repository.
This moves with you from one commit to the next.
The HEAD usually points to the last commit for a particular branch.
15) What does the 'git checkout' command do ?
This command is used to move around in the commit tree and moving your HEAD label.
This command will only change things in your local repository.
If your local repository does not have all the latest changes then you need to perform a 'git fetch' first.
You can move the HEAD label in lots of different ways
git checkout branch_name
git checkout HEAD^
git checkout HEAD~1
git checkout -b branch_name //creates a new branch and moves to that branch
16) Write code to remove an existing Remote Name
git remote rm remote_name
17) Write code that will throw away all my local changes and sync it with what is on the remote server
git reset --hard origin/branch_one
18) What is the base branch ?
This is a branch that others are being compared to.
19) What is the default branch ?
This is the branch that operations will be made on if you do not explicitly provide a branch name.
20) Write code to compare the files in the working directory with the files in the staging area ?
21) Write code to compare the files in the staging area with the files in the local repository ?
git diff --staged
22) Write code to create a local branch ?
git branch feature/newfeature
23) Write code to see the difference between a local branch and a remote branch ?
git diff develop remote_name/develop
24) Write code to merge the latest 'develop' changes to a feature branch ?
git fetch remote_name
git checkout feature/myfeature
git merge develop
25) Write code to merge a feature branch to the 'develop' branch ?
git checkout develop
git merge feature/myfeature
26) What does the 'git pull' command do ?
This command provides a shortcut to the following two lines of code.
Using the pull will not submit a merge commit
git pull develop
// equivalent to
git fetch develop //get all the latest information about all the branches on the remote server, no actual code
git merge develop //updates you local working copy and submits a merge commit
27) What does the 'git push -u' command do ?
It provides a shortcut to the following line of code
git push --set-upstream
This adds an upstream tracking reference
28) What does the 'git fetch --prune' command do ?
This will refresh your local copy of all the remote branches.
If any branches have been removed from the server they will be removed from your local copy.
git fetch --prune
29) What does the 'git revert' command do ?
This command can be used as a way of returning to a previous commit.
This can reverse the effect of earlier commits.
git revert -m 1 "commit id"
30) Is it possible to merge a branch with itself ?
Yes. Every merge will send a merge commit even when the merge has no changes.
31) What is 'VIM' ?
This is a command line text editor that can be used on any platform, windows, apple and unix
<esc>:wq<enter> //save and quit
© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext