There’re some requirements of submitting hw by git. Specially, this post is used to record all of the process.
Fristly, create a repository on your account. And don’t forget click the button permit clone or sth.
Secondly, get access to remote git.
Then, let’s do in command line.(before this, create a virtual environment)
$ which brew #determine if you have brew
#if not
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
#if it is
$ which git #determine if you have git
#if not
$ brew update && brew install git
#create a document
$ cd ~/documents
$ git clone ADDRESS
# rename the remote branch origin to upstream
$ git remote rename origin upstream
$ git remote set-url --push upstream anly-580
#now recreate the origin remote and point it to your private github repo, replacing <YOUR-GITHUB-HANDLE> with your Github username:
$ git remote add origin https://github.com/<YOUR-GITHUB-HANDLE>/GU-ANLY-580-FALL-2021.git
$ git remote --v #check if it is done
# push the cloned repository up to your remote
$ git push -u origin
Q:
- now passpord should be access token. you can find it in the settings>developer??>generate
- 删库只是删掉绑定关系,完全删除需要在GitHub上删掉,重新建的时候,记得把一开始的documents内容也清空
- fatal: not a git repository (or any of the parent directories): .git
两个原因,首先检查是不是在git 的文件夹下,也就是我们建立的documents而不是home。如果就是在对应文件下,那么运行git init
,会 initializes a new Git repository in your current working directory.
update some command lines:
cd ./documents/580
git add 文件名
git commit -m 提交
修改文件之后
git diff 文件名 可查看文件修改内容
git checkout --文件名 (把工作区的修改撤销,这样,文件就会回退到上一次提交时的状态)
push遇到的问题
1.Your name and email address were configured automatically based on your username and hostname
查了一下,由于苹果机用 iCloud 账户登录系统,很显然,默认提交账户被指定为 iCloud 相关账户了。
解决办法:
键入 git config --global user.name “你的 GitHub 用户名” 与 git config --global user.email “你的 GitHub 用户名对应的 email 地址”。然后再键入 git commit --amend --reset-author 即可。上修改完毕后再 push 到仓库中时,发现有一个新的branch??手动在repo删掉了多余的分支。
2.git提交时报错:Updates were rejected because the tip of your current branch is behind
解决办法:
3.Your branch is up to date with ‘origin/master’.同branch diverged问题
解决办法:
总结:git pull命令的作用是,取回远程主机某个分支的更新,再与本地的指定分支合并。而我在重复了git pull upstream main 时候,本地已有了分支,但与远程分支冲突,冲突在于我修改了quiz的一次作业。