Basic Git Commands 🖥️🖥️🖥️
In this module, we will learn about most used Git commands to get us basic knowledge to make our first contribution to source code.
The Commands 🖥️
git helpThis command list every possible commands that can be done along with different options that are availabe on Git.git helpgit help tutorialThis command opens a documentations about git commands and in-depth explanations of how they all work together.git help tutorialgit help <command>This command opens documentation for the single command passed in to it as an arguments.git help init-
This is to get and set repository or global options ```bash git configQuick notice : This requires the options like (–local, –global)
git initThis command creates an empty Git repository - basically a .git directory with subdirectories for objects, refs/heads, refs/tags, and template filesgit init
Quick notice: Ensure you are in the right directory/folder of your project before running this command.
git statusThis display the working tree status. It gives information about the changes and the state of the trackers.git statusgit addThis command adds file contents to the index(staging). This is the temporary addition of the contents into the staging environment.This command updates the index using the current content found in the working tree, to prepare the content staged for the next commit. a. Add everything in the directorygit add .b. Add a single or multiple individual files
git add file1 file2c. To add all
git add -Agit commitThis record changes permanently to the repository.git commit -m <message>git logThis is show commit logs. List commits that are reachable by following the parent links from the given commit(s), but exclude commits that are reachable from the one(s) given with a ^ in front of them. The output is given in reverse chronological order by default.git log-
git pushThis is to update remote refs along with associated objects. It is updates remote refs using local refs, while sending objects necessary to complete the given refs.bash git push git remoteThis manage set of tracked repositories. Manage the set of repositories (“remotes”) whose branches you track. With no arguments, shows a list of existing remotes. Several subcommands are available to perform operations on the remotes.git remote
Important Options: |-
git remote add[-t] [-m ] [-f] [--[no-]tags] [--mirror=(fetch|push)] |- ``git remote rename`` |- ``git remote remove``
git cloneThis clones a repository into a newly created directory, creates remote-tracking branches for each branch in the cloned repository (visible using git branch –remotes), and creates and checks out an initial branch that is forked from the cloned repository’s currently active branch.git clone-
git branchThis is to list, create, or delete branchesgit branch git checkoutThis is to switch branches or restore working tree filesgit checkoutPro tips: the branch as option
git mergeThis is used to join two or more development histories/branches together. Incorporates changes from the named commits (since the time their histories diverged from the current branch) into the current branch. This command is used by git pull to incorporate changes from another repository and can be used by hand to merge changes from one branch into another.git merge
Pro tips:
.gitignoreis a file that contain what is mearnt to not be tracking by git
Exercise
- Move into the University folder created in previous module.
- Initialize a git repository.
- Open
file and added 5 things about your school and save. - Add the file to index.
- Make a final commit.
« Previous Module<============================>Next Module »