I have a non-empty directory (eg /etc/something) with files that cannot be renamed, moved, or deleted.
I want to check this directory into git in place.
I want to be able to push the state of this repository to a remote repository (on another machine) using "git push" or something similar.
This is trivial using Subversion (currently we do it using Subversion) using:
svn mkdir <url> -m <msg> cd <localdir> svn co <url> . svn add <files etc> svn commit -m <msg>
What is the git equivalent?
Can I "git clone" into an empty directory and simply move the .git directory and have everything work?
git init Existing Folder For an existing project to become a Git repository, navigate into the targeted root directory. Then, run git init . Or, you can create a new repository in a directory in your current path. Use git init <directory> and specify which directory to turn into a Git repository.
Given you've set up a git daemon on <url>
and an empty repository:
cd <localdir> git init git add . git commit -m 'message' git remote add origin <url> git push -u origin master
This is how I do. I have added an explanation to understand what the heck is going on.
Initialize Local Repository
first, initialize Git with
git init
Add all Files for version control with
git add .
Create a commit with a message of your choice
git commit -m 'AddingBaseCode'
Initialize Remote Repository
Link Remote repo with Local repo
Now use copied URL to link your local repo with the remote GitHub repo. When you clone a repository with git clone, it automatically creates a remote connection called origin pointing back to the cloned repository. The command remote is used to manage a set of tracked repositories.
git remote add origin https://github.com/hiteshsahu/Hassium-Word.git
Synchronize
Now we need to merge local code with remote code. This step is critical otherwise we won't be able to push code on GitHub. You must call 'git pull' before pushing your code.
git pull origin master --allow-unrelated-histories
Commit your code
Finally, push all changes on GitHub
git push -u origin master
Note: Now Github uses "main" as the default branch. If your project use "main" instead of "master simply replace "master" with "main" from the above commands
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With