官术网_书友最值得收藏!

Code check-in

As we have the Git environment initialized in our local computer, we will proceed with a code check-in of a simple Python script:

  1.  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
  1. 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)

  1. 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
  1. 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 <abhishek.ratan@servicenow.com>

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.

  1. 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.
主站蜘蛛池模板: 乌兰县| 马龙县| 巨鹿县| 平凉市| 西城区| 丰镇市| 娄烦县| 嘉峪关市| 大庆市| 巴林左旗| 天全县| 兖州市| 秦皇岛市| 普洱| 潼南县| 株洲县| 泽普县| 调兵山市| 临泽县| 辽源市| 黎川县| 察哈| 普安县| 大同县| 通化县| 宿迁市| 天门市| 东乌| 芦山县| 邵阳县| 遂宁市| 潼南县| 崇仁县| 英山县| 博罗县| 林口县| 绥阳县| 久治县| 清徐县| 夹江县| 抚松县|