mkdir Allen_Guo_Rust_Learning_Note
cd Allen_Guo_Rust_Learning_Note
git init
git clone https://github.com/qingxiangguo/qingxiangguo.git
git status
Edit your files (e.g., using vim README.md
), then:
git add . # Add all changes to the staging area
git commit -m "Describe your changes here"
git push origin main
To switch to an existing branch:
git checkout branch_name
To create and switch to a new branch based on your current branch:
git checkout -b new_branch_name
git fetch
git merge origin/main
Alternatively, you can use:
git pull origin main
To see the commit history of your current branch:
git log
To view the commits that are in origin/main
but not in your local main
:
git log main..origin/main
To see the commit history of the main
branch in the origin
remote:
git log origin/main
rm file_to_delete.txt
git rm file_to_delete.txt
git commit -m "Remove file_to_delete.txt"
If you have initialized a local repository and want to connect it to a new remote repository:
- Create a new repo on GitHub.
- Copy the remote repository URL.
- Add the remote repository to your local one:
git remote add origin remote_repository_URL
git pull origin main
-
origin
is the default name given to the remote from which you have cloned your repository. It's essentially a shortcut to the remote repository's URL. -
main
is often the default branch name (previously it wasmaster
). When you see something likeorigin/main
, it refers to themain
branch on theorigin
remote.
Below is the revised markdown guide, incorporating the error messages you provided and an explanation of the git config pull.rebase false
setting, along with an overview of the differences between merge, rebase, and fast-forward:
Working with Git involves synchronizing your local changes with those in the remote repository. Conflicts arise when changes in both locations diverge. This guide will help you resolve conflicts using the merge strategy, which incorporates changes from the remote branch into your local branch.
When you attempt to push your local changes, you might encounter the following error:
! [rejected] main -> main (fetch first)
error: failed to push some refs to 'https://github.com/ylab-hi/SVoctopus.git'
hint: Updates were rejected because the remote contains work that you do not have locally.
This error indicates that there are commits in the remote repository that you don't have in your local branch.
When you try to pull changes with git pull origin main
, you may see an output like this:
remote: Enumerating objects: 15, done.
remote: Compressing objects: 100% (9/9), done.
From https://github.com/ylab-hi/SVoctopus
* branch main -> FETCH_HEAD
fatal: Need to specify how to reconcile divergent branches.
Git is alerting you that your local branch has diverged from the remote branch, and you need to specify how to reconcile them.
To tell Git to use merging to reconcile divergent branches, you can set the configuration:
git config pull.rebase false
This command sets the pull.rebase
option to false
, which instructs Git to merge changes by default when you pull
.
-
Merge (
git config pull.rebase false
): Merging creates a new commit in your history that combines the changes from the remote branch with your local branch. This "merge commit" has two parents, one pointing to the last commit on your branch and one to the commits pulled from the remote. -
Rebase (
git config pull.rebase true
): Rebasing rewrites your local branch's history by applying your changes on top of the remote branch's latest commit. This keeps a linear project history, as if you had made your local changes after the latest remote changes. -
Fast-Forward (
git config pull.ff only
): A fast-forward merge can only occur when there have been no changes in your local branch that the remote branch does not already have. It simply moves your branch pointer to match the remote's, avoiding a merge commit.
After configuring with git config pull.rebase false
, execute the pull command again:
git pull origin main
If there are conflicts, Git will pause and inform you which files need to be resolved manually.
Open the conflicting files, resolve the changes, and then add and commit them:
git add .
git commit -m "Resolve merge conflicts"
With the conflicts resolved and the merge complete, you can now successfully push your changes:
git push origin main