When a group of people is working on the same project then it's mandatory to have any version control system, so that everyone can work without having any conflict. Git is one of the popular distributed version control systems that we have.
There is some useful command...
To initialize a Git repository
git init
This command will create an empty Git repository or reinitialize an existing one. Basically, it creates a .git directory with subdirectories for objects, refs/heads, refs/tags, and template files. Also, an initial HEAD file that references the HEAD of the master branch.
To check modified and untracked files
Git Status
It will show all modified files first then untracked files i.e changes not staged for commit. Modified files are those files which are changed on the local machine and untracked files are the newly created files on the local machine and both are still to pushed on git repo.
For example
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: app/views/layouts/application.html.erb
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
Send file to Staging
git add <file>
This is used to add our files(modified or new) to staging i.e send on staging to commit. All the staged files path convert red to green after run this command i.e Changes to be committed:
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
modified: app/views/layouts/application.html.erb
The files listed here are in the Staging Area, and they are not in our repository yet. We could add or remove files from the stage before we store them in the repository.
git commit -m "<message for this commit>"
The output on console like
[master b0511c1] new commit
2 files changed, 17 insertions(+), 1 deletion(-)
create mode 100644 .gitignore
It's used to push our changes to git Repository (master branch)
git push origin master
The output like
Username for 'https://github.com': <username>
Password for 'https://<username>@github.com':
Counting objects: 12, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (7/7), 776 bytes | 0 bytes/s, done.
Total 7 (delta 3), reused 0 (delta 0)
To https://github.com/<username>/mytest.git
b9fc149..b0511c1 master -> master
Command to check modified/new files and push to master
Git Status
git add app/views/layouts/application.html.erb .gitignore
git commit -m "<message for this commit>"
Git Status
git push origin master(Provide your credential)
0 Comment(s)