GIT Exercises: Level Basic — Pagepro Blog


1. To initialize a Git repository here, type command.

git init

2. OK, let’s type git status to see what the current state of our project.

git status

3. Create file and called it example1.txt in the your folder. Run git status again and see how the repository status has changed.

git status

4. How Git says example1.txt is “untracked”? That means that example1.txt is a new file. Run git add example1.txt, it’s add file to the staging area. After this, Git starts to tracking choosed files.
(To adding all files of the same type you can run git add ‘*.(type of file)’ (example git add ‘*.txt’) )

git add example1.txt

5. Run git status again to check our changes.

git status

6. The files listed here are in the Staging Area, and they aren’t in our repo. At any moment we can add or remove files from this Area, before we store them in repo.

7. To store our Staging Area we run the git commit –m (commit with message describing what we’ve changed).

git commit –m “Add file name is example1”.

8. Run git log to see journal of remembers all the changes we’ve committed so far.

git log

9. To push our local repo to the GitHub server we’ll need to add a remote repository. Run command git remote add with that options (remote name and a repository URL)

git remote add origin

10. Remote repo name is origin and the name of default branch is master. Run git push to push our local changes to remote repo.

git push –u origin master

11. When we’ve invited other programmers to your repository, they can pulled your changes, made own commits, and pushed them. Then you can check changes others people and pull down any new changes.

git pull origin master

12. To take a look at what is different from your last commit use git diff command. Use HEAD pointer to diff of our most recent commit.

git diff HEAD

13. Run git diff with the ––staged option to see option to see the changes you just staged.

git diff ––staged

14. To unstage files using git reset command.

git reset 'file name'

15. When programmers are working on a feature or bug they often create a copy or the code can make separate commits to. Create a branch called new_branch_2.

git branch new_branch_2

16. To switch branches using command git checkout ‘name of branch’. Try it to switch to the new_branch_2.

git checkout new_branch_2

17. To remove files using git rm command. That will not only remove the actual files form disk, but will also stage the removal of the files for us. To remove all files of that type use git rm ‘*.(type of file).

git rm '*.txt'

18. Commit this changes.

git commit –m 'Remove all txt files'

19. Switch branch to master branch.

git checkout master

20. When you have to merge your changes form new_branch_2 into the master branch use git merge.

git merge new_branch_2

21. If you merge branches and repair some bugfix can you remove branch that you don’t need anymore. Run git branch –d ‘branch name’ to delete a branch. Try do this.

git branch –d new_branch_2
Leave a Reply

View Comments (0)...

Related articles:

Front-end Internship: Day 6&7 — The Pagepro Way

Best Books for Junior Developers to Boost Their Career