配置git信息
git config --global user.name 'your name' # 配置名字信息,例如,你的github用戶名
git config --global user.email 'your email' # 配置郵箱,例如,你的github註冊郵箱
git config --gloabl credential.helper cache
git config --gloabl credential.helper 'cache --timeout=3600' # 配置超時時間
新建git倉庫
要先去github上新建一個倉庫(repo),建好後可以得到該倉庫的地址,其格式形如 https://github.com/your_user_name/new_repo_name.git ,在github倉庫主目錄上點擊Clone or download,即可看到該repo的地址。
之所以要這樣,是因爲據我的測試,在本地是無法直接新建repo的,只能先在github上新建好一個repo後,然後在本地通過命令與該遠程repo相關聯。
在本地新建倉庫並與遠程repo相關聯
git init # 在本地初始化git
touch README # 爲該倉庫新建一個README文件
git add README # 將該文件添加到git緩衝區
git commit -m 'add readme' # 提交到緩衝區,-m表示message,後面接的是提交信息
git remote add origin https://github.com/user_name/epo_name.git # 添加遠程源repo
git push origin master # 將更新同步到master分支 # 此處將README文件同步到遠程的repo中
其他
git checkout -b dev # 創建新分支dev並切換至dev分支
git checkout master # 切換回master分支
git branch -a # 獲取所有分支信息
git config --list # 獲取本地git的配置信息(用戶名、郵箱等)
git remote -v # 查看遠程repo的地址