Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between working directory and local repository?

I've created a new GitHub repository. I'm quite confused by working directory and local repository. When working on my own, my stuff all resides on working directory. But when work with repo, I should check my stuff there. But are they the same thing? or should they be separate. Then how to commit my stuff in working directory to my local repo. How to commit my local repo to remote repo. How to do this by Git Bash? Thanks!

like image 864
Zoe Avatar asked Feb 11 '14 02:02

Zoe


People also ask

What is the difference between local repository and remote repository?

Local repositories reside on the computers of team members. In contrast, remote repositories are hosted on a server that is accessible for all team members - most likely on the internet or on a local network.

What is the use of local repository?

This "local repository" keeps track of the files in the working directory, the staging area/index where files get added, and the HEAD where it points to the most recent commit.

What are local repositories?

Local repositories are physical, locally-managed repositories into which you can deploy artifacts. Using local repositories, Artifactory gives you a central location to store your internal binaries. Through repository replication, you can even share binaries with teams that are located in remote locations.

What is a working directory in Git?

You can access the commit history with the Git log. The working tree, or working directory, consists of files that you are currently working on. You can think of a working tree as a file system where you can view and modify files. The index, or staging area, is where commits are prepared.


1 Answers

Working directory is the directory with your source files under git control (in the root of all dirs under control .git file is present). Git is tracking the difference between your working directory and local repository, and between your local repository and (one of) remote repositories.

To see what was changed, use $ git status.

To commit your changes (edits and/or new files) to the local repository, use $ git add and then $ git commit.

To see what was committed use $ git log.

Then, if you want to commit your changed to the remote repository, use $ git push.

Pay attention to what git commands are printing, it often contain advice what to do.

If you are working with GitHub, their help is also useful: pushing to a remote.

Good basic information is also in atlassian site.


FOR EXAMPLE:

Suppose, you initiated your git repository with $ git init in JavaRepo dir and checkouted there the project with $ git pull or $ git clone. Then JavaRepo should contain .git file (among others git dotted files) - you can check it with $ ls -a. These files itself are the local git repository, and there is no need to distinguish 'working directory' and 'local repository' directory.

So, start working with files in JavaRepo: say you changed file example.java and created new file example2.java. Execute $ git status in JavaRepo (or in any its subdirs). It should show: 'modified: example.java', 'Untracked files: example2.java'.

Add your files to the staging area with $ git add example.java and $ git add example2.java commands from the directory with these files. (Notice that $ git add is both for changed and new files.)

And finally commit your files by $ git commit -m "example changes" (-m stays for message - comments to the commit).

$ git log should show this commit.

like image 144
Spock77 Avatar answered Sep 17 '22 09:09

Spock77