Over a million developers have joined DZone.

Git - Simple File Management

· Agile Zone

Learn more about how DevOps teams must adopt a more agile development process, working in parallel instead of waiting on other teams to finish their components or for resources to become available, brought to you in partnership with CA Technologies.

Files can be added, committed and removed from git repositories using one or more of the following commands:

Adding a file named "testFile.xml" to the index.

git add testFile.xml

Testing to view differences between the index and HEAD

git diff --cached

produces something like the following:

lizard:l8mdv-si-samples mvickery$ git diff --cached
diff --git a/testFile.xml b/testFile.xml
new file mode 100644
index 0000000..e69de29

This has not been added to the repository yet but remains in the index. Committing the file to the local repository involves promoting changes from the index to the repository, a suitable command could be something like:

git commit -m "Creating content" testFile.xml

Assuming no other files have been created and added to the index, running "git diff -- cached" after performing the commit should result in nothing being returned from the command invocation. The index and HEAD are now synchronised.

The local repository contains the new file, if you're using GitHub you may want to push the new file to the remote repository, this can be done with a command such as the following:

git push -u origin master

Additionally, if you're using GitHub as a remote repository, you can remove files from that repository by using a commands such as the following:

Removal from index, local repositoryremote repository and the local file system:

git rm testFile.xml
git commit -m "Test file removal"
git push -u origin master

Removal from the index, local repository, remote repository but not the local file system:

git rm --cached testFile.xml
git commit -m "Test file removal"
git push -u origin master

Discover the warning signs of DevOps Dysfunction and learn how to get back on the right track, brought to you in partnership with CA Technologies.

Topics:

Published at DZone with permission of Matt Vickery, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}