Tuesday, 19 April 2016

Version Controller : Git - Basic Git commands

Open Git Bash.

git config --global user.name "Your Name"
git config --global user.email name@yourdomain.com
This step is important since the above details will appear when you commit modifications in the repository. In this way your collaborators will know who has updated the repository content.

Initialize a new GIT repository:
user@user:/GIT/test# git init

An empty Git repository is initialized: /GIT/test/.git
Create a file in the working folder:
user@user:/GIT/test# touch README
You can check the status of files in the index versus the working directory:
user@user:/GIT/test# git status
# On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # README nothing added to commit but untracked files present (use "git add" to track)
Next, add the newly created file to the index:
user@user:/GIT/test# git add README
Once again check the status of the files in the index versus the working directory:
user@user:/GIT/test# git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file:
README Proceed with the first commit:
user@user:/GIT/test# git commit -m 'first commit' [master (root-commit)

84f241e] first commit 0 files changed, 0 insertions(+), 0 deletions(-)

create mode 100644 README
Check the status after the commit operation:
user@user:/GIT/test# git status # On branch master nothing to commit (working directory clean)
Add the remote repository to your existing local one:
user@user:/GIT/test# git remote add origin git@github.com:user/test.git
Push the modification to the remote repository:
user@user:/GIT/test# git push origin master Counting objects: 3, done.

Writing objects: 100% (3/3), 207 bytes, done. Total 3 (delta 0),

reused 0 (delta 0) To git@github.com:user/test.git * [new branch] master -> master

You can log in your GitHub account and check the newly pushed file:



No comments:

Post a Comment