#git-basics
#assembler-institute
#master-in-software-development
With these exercises you will learn how to use git in your console.
Git is a version control software designed by Linus Torvalds, thinking about the efficiency and reliability of maintaining application versions when they have a large number of source code files. Its purpose is to keep track of changes in computer files and coordinate the work that several people do on shared files.
- Understand what version control is and what it is used for
- Understand what GIT is and its fundamentals
- Become familiar with repositories
The first step is to install git to start using it. To do this, follow the steps indicated in the official guide:
It is important that once installed, you configure GIT correctly, to do this follow the steps indicated in the official guide:
Next, you will need to follow the instructions to complete the exercises:
1.2.0 Clone the repository to create a local copy on your computer: https://github.com/assembler-institute/git-basics-1.git
1.2.1 exercise-01: Create a new file and add it to the staging area
- Create a new file named:
exercise-01.txt
inside thesrc/exercises folder
- Add any text value inside the new file and save the new file
- Add the file to the staging index with the
git add 'file-name'
command - Execute the:
npm run validate-exercise-01
command from the terminal to validate your solution to the exercise
1.2.2 exercise-02: Create a commit with the new file
- Use the
git commit -m 'commit-message'
command to create a new commit based on the changes in the staging area that have the new file you just created - Use a commit message of:
'exercise-02 commit'
- Execute the:
npm run validate-exercise-02
command from the terminal to validate your solution to the exercise
1.2.3-a exercise-03-a: Create 2 new files and add all of them to the staging area
- Create 2 new files inside the
src/exercises
folder with the names of:exercise-03-a.txt
exercise-03-b.txt
- Add any text value inside each file and save them
- Add all of them to the staging area with the
git add --all
command - Execute the:
npm run validate-exercise-03-a
command from the terminal to validate your solution to the exercise
1.2.3-b exercise-03-b: Create a new commit with the new files
- Create a commit with all the new files with the commit message of:
'exercise-03 commit'
- Execute the:
npm run validate-exercise-03-b
command from the terminal to validate your solution to the exercise
1.2.4-a exercise-04-a: Make a change and add it to the staging index
- Change the content of the
exercise-03-a.txt
file and add the changes to the staging index with thegit add
command - Execute the:
npm run validate-exercise-04-a
command from the terminal to validate your solution to the exercise
1.2.4-b exercise-04-b: Use git reset to unstage the changes
- Run the
git reset HEAD src/exercises/exercise-03-a.txt
command to unstage the changes from the staging index - Now you should see that the changes were added back to the working directory and out of the staging index
- Execute the:
npm run validate-exercise-04-b
command from the terminal to validate your solution to the exercise
1.2.5 exercise-05: Use git checkout -- to discard all the changes made to a file
- Run the GIT command to discard the changes made to the file:
git checkout HEAD -- src/exercises/exercise-03-a.txt
- This command will remove all the changes you made to the file and they will be deleted. This is useful if you don’t want to keep the changes that you made so far.
- NOTE: This command removes the changes, you will not be able to recover them once they are removed.
- Execute the:
npm run validate-exercise-05
command from the terminal to validate your solution to the exercise
1.3.1 exercise-06: Create a new branch named develop
- Execute the
git branch
command to see the branch you are currently in - Create a new branch named
develop
with the git command:git branch develop
- Execute the
git branch
command to see a list of the branches - Execute the:
npm run validate-exercise-06
command from the terminal to validate your solution to the exercise
1.3.2 exercise-07: Switch to the develop branch and create a new commit
- Execute the
git checkout 'branch-name'
command to switch to the new branch you just created:git checkout develop
- Create a new file named
exercise-07.txt
in the thesrc/exercises
folder that has any value inside and create a new commit with the new file - Execute the:
npm run validate-exercise-07
command from the terminal to validate your solution to the exercise
1.3.3 exercise-08: Create a new branch named feature
based on the develop
branch
- Create a new branch named
feature
based on the branchdevelop
- Switch to the
master
branch usingcheckout
- Execute the:
npm run validate-exercise-08
command from the terminal to validate your solution to the exercise
1.3.4 exercise-09: Delete the branch feature
- Execute the
git branch -D 'branch-name'
command to remove thefeature
branch from the previous exercisesgit branch -D feature
- This command removes a branch
- Execute the:
npm run validate-exercise-09
command from the terminal to validate your solution to the exercise
1.3.5 exercise-10: Make a merge commit in the master
branch from the develop branch
- You should be in the master branch before you continue with the next steps
- Create a new file in the master branch named
exercise-10.txt
in thesrc/exercises
folder that has any value inside - Create a new commit with the new file in the master branch
- Make a new commit in the master branch that merges the commits from the develop branch with the command:
git merge develop
- This will create a new merge commit with the commits from the develop and master branches
- Execute the:
npm run validate-exercise-10
command from the terminal to validate your solution to the exercise
1.4.1 exercise-11: Create a new stash entry without a message
- Change the contents of the
exercise-03-a.txt
file and save the file - Run the GIT command to create a new stash entry without a message:
git stash push
- This command will create a new stash entry with the changes that you made to the file.
- Then you can use the
git stash list
command to see a list of all the stash entries that you made, or the thegit stash show stash@{0}
command to see the files that were affected by the stash entry number 0 - Stash entries are 0 indexed like arrays
- If you’d like to see the changes made in the stash you can use the following command to see the code changes in the stash entry:
git stash show --patch stash@{0}
- Execute the:
npm run validate-exercise-11
command from the terminal to validate your solution to the exercise
1.4.2 exercise-12: Remove the stash entry and apply the changes again
- Run the GIT command to remove the stash entry from the stash and apply the changes to the working directory
git stash pop
- This command will remove the latest stash entry from the stash and apply the changes in the working directory.
- Execute the:
npm run validate-exercise-12
command from the terminal to validate your solution to the exercise
1.4.3 exercise-13: Create a new stash entry with a message
- Create a new stash entry with the changes made to the
exercise-03-a.txt
file from the previous steps - Run the GIT command to create a new entry that has a message
git stash push -m 'stash-message'
- Use a stash message of
'my stash message'
- This will create a new stash entry like the exercise-11 but one that has message that you define
- Execute the:
npm run validate-exercise-13
command from the terminal to validate your solution to the exercise
1.4.4 exercise-14: Clear the stash list
- Run the GIT command to remove all the stash entries from the stash
git stash clear
- This will remove all the stash entries from the stash
- Execute the:
npm run validate-exercise-14
command from the terminal to validate your solution to the exercise
1.4.5 exercise-15: Create a new file and store it in a stash entry
- Create a new file named
exercise-15.txt
in thesrc/exercises
folder and store any text value inside - Run the GIT command to create a new stash entry that also stashes files that are not tracked by GIT with a stash message of:
'stash with untracked files'
git stash push --include-untracked -m 'your message'
- Execute the:
npm run validate-exercise-15
command from the terminal to validate your solution to the exercise
- You must perform all the steps using only the command line
- You must upload the repository with the exercises to your Github repository once you are finished
- You will have to learn how to connect to the Github platform using the terminal so that you can push the local repository
Before uploading the local repository with the exercise files to the remote repository you will need to:
- Create a new empty repository which you will use to push the exercise files
- Once you have created the empty repository, you should see a screen with the instructions of adding the remote url of the repository.
- Copy the
git remote add origin https://…
(this is your repository URL) - Execute the following command to remove the existing remote origin of your local repository:
git remote remove origin
- You can execute the following command to see a list of the current remote URLs in your local repository:
git remote -v
- Add the remote repository URL from your GitHub as the new origin of your local repository
- Execute the following Git command to push the local repository
git push --set-upstream origin master
- The:
--set-upstream
command (or the shorthand version-u
) sets the remote origin URL to be of typetracking
so that thegit push
,pull
andfetch
commands use that remote URL as the default one
The following deliverables will be necessary to evaluate the project:
- The repo uploaded to Github with the solutions of the exercises