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 help
This command list every possible commands that can be done along with different options that are availabe on Git.git help
git help tutorial
This command opens a documentations about git commands and in-depth explanations of how they all work together.git help tutorial
git 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 config
Quick notice : This requires the options like (–local, –global)
git init
This 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 status
This display the working tree status. It gives information about the changes and the state of the trackers.git status
git add
This 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 file2
c. To add all
git add -A
git commit
This record changes permanently to the repository.git commit -m <message>
git log
This 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 push
This 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 remote
This 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 clone
This 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 branch
This is to list, create, or delete branchesgit branch
git checkout
This is to switch branches or restore working tree filesgit checkout
Pro tips: the branch as option
git merge
This 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:
.gitignore
is 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 »