Skip to main content
fixed another occurrence of "master"
Source Link

This is how I would do it:

$ git init .
$ git remote add origin [url of the repo]
$ git fetch origin
$ git push --set-upstream origin main
$ git branch -f main origin/main

(concerning the last command, see also Move branch pointer to different commit without checkout and https://www.kernel.org/pub/software/scm/git/docs/git-branch.html which describes the idea).

This works, as git is comparing the SHA1 value of the files in your working directory, which is based on the filename and the content. To prove that it worked, you may run git diff which will not show any difference (assuming that you really kept the directory in sync with the repo). We can also prove this:

$ git hash-object testfile.txt
77356c31404cfbc88ab78de4025ebd609c022927

$ ls -a .git/objects/77/*
.git/objects/77/356c31404cfbc88ab78de4025ebd609c022927

Note that we now have

  • a proper working directory and
  • a proper branch configuration, which points to the same content.

However, the staging area still is out of sync. That is why another

$ git add -A 

is required (Keep in mind that this operation may become costly if you have many or large files, as all files will be added to the repositories' index). This will synchronize your staging area as well. A git status then will yield:

On branch mastermain
Your branch is up-to-date with 'origin/main'.
nothing to commit, working directory clean

This is how I would do it:

$ git init .
$ git remote add origin [url of the repo]
$ git fetch origin
$ git push --set-upstream origin main
$ git branch -f main origin/main

(concerning the last command, see also Move branch pointer to different commit without checkout and https://www.kernel.org/pub/software/scm/git/docs/git-branch.html which describes the idea).

This works, as git is comparing the SHA1 value of the files in your working directory, which is based on the filename and the content. To prove that it worked, you may run git diff which will not show any difference (assuming that you really kept the directory in sync with the repo). We can also prove this:

$ git hash-object testfile.txt
77356c31404cfbc88ab78de4025ebd609c022927

$ ls -a .git/objects/77/*
.git/objects/77/356c31404cfbc88ab78de4025ebd609c022927

Note that we now have

  • a proper working directory and
  • a proper branch configuration, which points to the same content.

However, the staging area still is out of sync. That is why another

$ git add -A 

is required (Keep in mind that this operation may become costly if you have many or large files, as all files will be added to the repositories' index). This will synchronize your staging area as well. A git status then will yield:

On branch master
Your branch is up-to-date with 'origin/main'.
nothing to commit, working directory clean

This is how I would do it:

$ git init .
$ git remote add origin [url of the repo]
$ git fetch origin
$ git push --set-upstream origin main
$ git branch -f main origin/main

(concerning the last command, see also Move branch pointer to different commit without checkout and https://www.kernel.org/pub/software/scm/git/docs/git-branch.html which describes the idea).

This works, as git is comparing the SHA1 value of the files in your working directory, which is based on the filename and the content. To prove that it worked, you may run git diff which will not show any difference (assuming that you really kept the directory in sync with the repo). We can also prove this:

$ git hash-object testfile.txt
77356c31404cfbc88ab78de4025ebd609c022927

$ ls -a .git/objects/77/*
.git/objects/77/356c31404cfbc88ab78de4025ebd609c022927

Note that we now have

  • a proper working directory and
  • a proper branch configuration, which points to the same content.

However, the staging area still is out of sync. That is why another

$ git add -A 

is required (Keep in mind that this operation may become costly if you have many or large files, as all files will be added to the repositories' index). This will synchronize your staging area as well. A git status then will yield:

On branch main
Your branch is up-to-date with 'origin/main'.
nothing to commit, working directory clean

This is how I would do it:

$ git init .
$ git remote add origin [url of the repo]
$ git fetch origin
$ git push --set-upstream origin mastermain
$ git branch -f mastermain origin/mastermain

(concerning the last command, see also Move branch pointer to different commit without checkout and https://www.kernel.org/pub/software/scm/git/docs/git-branch.html which describes the idea).

This works, as git is comparing the SHA1 value of the files in your working directory, which is based on the filename and the content. To prove that it worked, you may run git diff which will not show any difference (assuming that you really kept the directory in sync with the repo). We can also prove this:

$ git hash-object testfile.txt
77356c31404cfbc88ab78de4025ebd609c022927

$ ls -a .git/objects/77/*
.git/objects/77/356c31404cfbc88ab78de4025ebd609c022927

Note that we now have

  • a proper working directory and
  • a proper branch configuration, which points to the same content.

However, the staging area still is out of sync. That is why another

$ git add -A 

is required (Keep in mind that this operation may become costly if you have many or large files, as all files will be added to the repositories' index). This will synchronize your staging area as well. A git status then will yield:

On branch master
Your branch is up-to-date with 'origin/master'main'.
nothing to commit, working directory clean

This is how I would do it:

$ git init .
$ git remote add origin [url of the repo]
$ git fetch origin
$ git push --set-upstream origin master
$ git branch -f master origin/master

(concerning the last command, see also Move branch pointer to different commit without checkout and https://www.kernel.org/pub/software/scm/git/docs/git-branch.html which describes the idea).

This works, as git is comparing the SHA1 value of the files in your working directory, which is based on the filename and the content. To prove that it worked, you may run git diff which will not show any difference (assuming that you really kept the directory in sync with the repo). We can also prove this:

$ git hash-object testfile.txt
77356c31404cfbc88ab78de4025ebd609c022927

$ ls -a .git/objects/77/*
.git/objects/77/356c31404cfbc88ab78de4025ebd609c022927

Note that we now have

  • a proper working directory and
  • a proper branch configuration, which points to the same content.

However, the staging area still is out of sync. That is why another

$ git add -A 

is required (Keep in mind that this operation may become costly if you have many or large files, as all files will be added to the repositories' index). This will synchronize your staging area as well. A git status then will yield:

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

This is how I would do it:

$ git init .
$ git remote add origin [url of the repo]
$ git fetch origin
$ git push --set-upstream origin main
$ git branch -f main origin/main

(concerning the last command, see also Move branch pointer to different commit without checkout and https://www.kernel.org/pub/software/scm/git/docs/git-branch.html which describes the idea).

This works, as git is comparing the SHA1 value of the files in your working directory, which is based on the filename and the content. To prove that it worked, you may run git diff which will not show any difference (assuming that you really kept the directory in sync with the repo). We can also prove this:

$ git hash-object testfile.txt
77356c31404cfbc88ab78de4025ebd609c022927

$ ls -a .git/objects/77/*
.git/objects/77/356c31404cfbc88ab78de4025ebd609c022927

Note that we now have

  • a proper working directory and
  • a proper branch configuration, which points to the same content.

However, the staging area still is out of sync. That is why another

$ git add -A 

is required (Keep in mind that this operation may become costly if you have many or large files, as all files will be added to the repositories' index). This will synchronize your staging area as well. A git status then will yield:

On branch master
Your branch is up-to-date with 'origin/main'.
nothing to commit, working directory clean
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

This is how I would do it:

$ git init .
$ git remote add origin [url of the repo]
$ git fetch origin
$ git push --set-upstream origin master
$ git branch -f master origin/master

(concerning the last command, see also Move branch pointer to different commit without checkoutMove branch pointer to different commit without checkout and https://www.kernel.org/pub/software/scm/git/docs/git-branch.html which describes the idea).

This works, as git is comparing the SHA1 value of the files in your working directory, which is based on the filename and the content. To prove that it worked, you may run git diff which will not show any difference (assuming that you really kept the directory in sync with the repo). We can also prove this:

$ git hash-object testfile.txt
77356c31404cfbc88ab78de4025ebd609c022927

$ ls -a .git/objects/77/*
.git/objects/77/356c31404cfbc88ab78de4025ebd609c022927

Note that we now have

  • a proper working directory and
  • a proper branch configuration, which points to the same content.

However, the staging area still is out of sync. That is why another

$ git add -A 

is required (Keep in mind that this operation may become costly if you have many or large files, as all files will be added to the repositories' index). This will synchronize your staging area as well. A git status then will yield:

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

This is how I would do it:

$ git init .
$ git remote add origin [url of the repo]
$ git fetch origin
$ git push --set-upstream origin master
$ git branch -f master origin/master

(concerning the last command, see also Move branch pointer to different commit without checkout and https://www.kernel.org/pub/software/scm/git/docs/git-branch.html which describes the idea).

This works, as git is comparing the SHA1 value of the files in your working directory, which is based on the filename and the content. To prove that it worked, you may run git diff which will not show any difference (assuming that you really kept the directory in sync with the repo). We can also prove this:

$ git hash-object testfile.txt
77356c31404cfbc88ab78de4025ebd609c022927

$ ls -a .git/objects/77/*
.git/objects/77/356c31404cfbc88ab78de4025ebd609c022927

Note that we now have

  • a proper working directory and
  • a proper branch configuration, which points to the same content.

However, the staging area still is out of sync. That is why another

$ git add -A 

is required (Keep in mind that this operation may become costly if you have many or large files, as all files will be added to the repositories' index). This will synchronize your staging area as well. A git status then will yield:

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

This is how I would do it:

$ git init .
$ git remote add origin [url of the repo]
$ git fetch origin
$ git push --set-upstream origin master
$ git branch -f master origin/master

(concerning the last command, see also Move branch pointer to different commit without checkout and https://www.kernel.org/pub/software/scm/git/docs/git-branch.html which describes the idea).

This works, as git is comparing the SHA1 value of the files in your working directory, which is based on the filename and the content. To prove that it worked, you may run git diff which will not show any difference (assuming that you really kept the directory in sync with the repo). We can also prove this:

$ git hash-object testfile.txt
77356c31404cfbc88ab78de4025ebd609c022927

$ ls -a .git/objects/77/*
.git/objects/77/356c31404cfbc88ab78de4025ebd609c022927

Note that we now have

  • a proper working directory and
  • a proper branch configuration, which points to the same content.

However, the staging area still is out of sync. That is why another

$ git add -A 

is required (Keep in mind that this operation may become costly if you have many or large files, as all files will be added to the repositories' index). This will synchronize your staging area as well. A git status then will yield:

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
language editing
Source Link
Loading
Source Link
Loading