Last active
December 19, 2015 03:59
-
-
Save arganzheng/5894485 to your computer and use it in GitHub Desktop.
Git常用命令备忘录
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
如果你本地工程已经是一个Git Repository(已经执行过[Import an existing, unversioned code project to an empty repository]),那么可以这样把它加入你在Bitbucket创建的远程仓库中: | |
cd /path/to/my/repo | |
# Creates a remote named "origin" pointing at your GitHub/Bitbucket repository (设置远程仓库地址) | |
git remote add origin ssh://[email protected]/arganzheng/remote-terminator.git | |
# Sends your commits in the "master" branches to GitHub/Bitbucket | |
git push -u origin master | |
当然在你能push之前必须先设置你的账号信息,并且最好使用Password Caching或者SSH key避免每次提交代码都要提示输入密码。 | |
1. 设置账号信息 | |
# Sets the default name for git to use when you commit | |
git config --global user.name "arganzheng" | |
# Set the default email for git to use when you commit | |
git config --global user.email "[email protected]" | |
注意:这里设置的账户信息必须与远程仓库(github/bitbucket)账户信息一致,因为是用于权限认证的。 | |
2. 使用Password Caching或者SSH key避免每次提交代码都要提示输入密码 | |
Github推荐使用Password Caching with HTTPS方式 [Set Up Git](https://help.github.com/articles/set-up-git) | |
Github和Bitbucket都支持使用SSH key验证: | |
Github: [Generating SSH Keys](https://help.github.com/articles/generating-ssh-keys) | |
Bitbucket: [Set up SSH for Git](https://confluence.atlassian.com/display/BITBUCKET/Set+up+SSH+for+Git) | |
两者的步骤其实都是一样的。 | |
使用SSH Keys方式最后记得先验证一下: | |
ssh -T [email protected] | |
ssh -T [email protected] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you hava code on your local machine that is not under source control, you can put it under source control and import it into BitBucket: | |
1. [Set up Git](https://confluence.atlassian.com/x/X5wXE?utm_source=internal&utm_medium=link&utm_campaign=blank_repo) on your machine if you haven't already. | |
2. cd /path/to/your/project or mkdir /path/to/your/project if start from scratch. | |
3. Initialize the driectory under source control | |
git init | |
4. Stages the current directory, adding it to the list of files to be committed | |
git add . | |
5. Commits your files | |
git commit -m "message" | |
这样子本地就是一个git repo,接下来就是去Bitbucket或者Github上创建一个远程仓库,然后将本地提交push过去。具体参见上一条gist[Import an existing repository to Bitbucket]。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Git常用命令备忘 robbin的这篇文章是个不错的git命令手册