Thursday, April 27, 2017

Initializing git repository and adding files



Initialize an empty git repository in the current folder.
git init .

Add files in the current folder to git so that it can track it.
git add .

Commit all the files that have been modified or added.
git commit -m "My first commit"

If you want to add and commit together, you can use -am option as shown below.
git commit -a -m <message>

But remember that this option only works for files already tracked by git not for newly added files.

Now whenever you modify files and want to add it to the git repository, you have to add the files using git add and commit using git commit.

So far you are able to create repository locally but in most practical circumstances repository resides in a server.
In order to push yur code to the server, you have to first add the server using following git command:

git remote add <name of the remote> <url>

After this you can do:

git push

to publish your changes to the server.

No comments:

Post a Comment

Overriding a remote branch in git

If you need to override a remote branch with local changes, then you can use: git push -f This is very useful whenever you need to disc...