As we have the Git environment initialized in our local computer, we will proceed with a code check-in of a simple Python script:
- Confirm that the file that needs to be checked in exists in the folder:
Directory of C:\test\mytest
12-Nov-18 03:16 PM <DIR> .
12-Nov-18 03:16 PM <DIR> ..
12-Nov-18 03:12 PM 0 git
12-Nov-18 03:16 PM 34 myfirstcodecheckin.py
2 File(s) 34 bytes
2 Dir(s) 345,064,542,208 bytes free
- If the file has not been added to git, it would show up in the git status command under untracked files:
C:\test\mytest>git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
git
myfirstcodecheckin.py
nothing added to commit but untracked files present (use "git add" to track)
- Add this file for the code check-in and validate it again using git status (the added file will now show under the Changes to be committed section):
C:\test\mytest>git add myfirstcodecheckin.py
C:\test\mytest>git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: myfirstcodecheckin.py
Untracked files:
(use "git add <file>..." to include in what will be committed)
git
- Commit this particular change to the master (in other words, ensure the local copy is now saved on the server, ready to be shared with others):
C:\test\mytest>git commit -m "this is a test checkin"
[master (root-commit) abe263d] this is a test checkin
Committer: Abhishek Ratan <[email protected]>
1 file changed, 1 insertion(+)
create mode 100644 myfirstcodecheckin.py
The -m in this section specified a comment for this particular code check-in. This generally depicts what code is being checked in and is treated like a remark section for this particular check-in.
- We need to push our changes back to the server hosted on the web:
C:\test\mytest>git push
Counting objects: 3, done.
Writing objects: 100% (3/3), 273 bytes | 273.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote: https://github.com/pnaedition2/mytest/pull/new/master
remote:
To https://github.com/pnaedition2/mytest.git
* [new branch] master -> master
This completes the check-in process for a specific file (or code script). To confirm that the process was successful, we can go to the GitHub URL of your repository to see the file:
As a final note, the next time someone clones the Git repository on a different machine, they just need to do a simple git pull for the same files to be visible and as a local copy on that particular machine. A similar approach can be followed for subsequent check-ins, as well as modifications to current files.
As best practice, always perform git pull before git push, to ensure you have the updated code in your local repository before your push out any code back to the main repository.