Add Files or Folders to Git Repository

Posted on

Another article for describing on how to add files or folder recursively inside a folder which has already been initialized as a Git repository is the focus of the discussion on this article. So, make sure that the folder which has files or folders inside of it has already been initialized as a Git repository. To be able to check whether a folder has already been initialized as a Git repository or not, it can be checked in this article titled ‘Setup a Git Repository via Command Line‘ exists in this link.

There are several steps which is needed to be taken, in the context of this article for an instance┬áto make sure that the folder where files or folders located inside of it is already initialized. To learn how to initialize or to associate a folder with Git repository for further operation and manipulation, just read the article ‘Setup a Git Repository via Command Line‘ which exist in this link.

So, after initializing the folder where files and folders are going to be added to the Git repository, follow the steps below to add files or folders to a Git Repository.

1. Check whether the ‘git’ utility has already been installed. Depends on the operating system’s version, how to check the ‘git’ utility for an example in an Ubuntu Linux distribution can be viewed in the article titled ‘Setup a Git Repository via Command Line‘ where it can be visited in this link.

2. To be able to prove that the ‘git’ utility has already been installed, just type the following command on the bash prompt :

Checking the git version :

git --version

For an example :

user@hostname:/var/www/html/test# git --version
git version 2.7.4
You have new mail in /var/mail/root
user@hostname:/var/www/html/test# 

Checking the full feature of git utility by executing the following command :

git

For an example :

user@hostname:/var/www/html/test# git
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
clone Clone a repository into a new directory
init Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
add Add file contents to the index
mv Move or rename a file, a directory, or a symlink
reset Reset current HEAD to the specified state
rm Remove files from the working tree and from the index

examine the history and state (see also: git help revisions)
bisect Use binary search to find the commit that introduced a bug
grep Print lines matching a pattern
log Show commit logs
show Show various types of objects
status Show the working tree status

grow, mark and tweak your common history
branch List, create, or delete branches
checkout Switch branches or restore working tree files
commit Record changes to the repository
diff Show changes between commits, commit and working tree, etc
merge Join two or more development histories together
rebase Forward-port local commits to the updated upstream head
tag Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
fetch Download objects and refs from another repository
pull Fetch from and integrate with another repository or a local branch
push Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
user@hostname:/var/www/html/test#

3. After successfully executed the ‘git’ command, to add files or folders inside the already initialized folder named ‘test’, execute the following command inside the ‘test’ folder :

user@hostname:/var/www/html/test# git add .
user@hostname:/var/www/html/test# 

The process for adding files and directories for all files and directories inside the directory named ‘test’ is done. But the process itself for passing the files and folders to Git repository server is not finished. The next process is to commit the files and folders which already been added. To be able to do it, just read the article titled ‘Commit Files or Folders to a Git Repository‘ which exist in this link.

One thought on “Add Files or Folders to Git Repository

Leave a Reply