When using git, how do you push the exact working directory to the remote?

I have a remote git repository and a local clone. Let's say I lose the local .git directory, and then add and delete some files to the local working directory.

At some point, I want to restart the local repo, connect it to the remote computer and, ultimately, direct the local working directory to remote access exactly as it is (that is, I want all the added / deleted files to be same on the remote control)

How to do it?

Here is my current solution that I don't like (and may not work in all cases).

git init

git remote incremental source [some_url]

git add. # adds all files to the working directory

git commit -m "add files"

(At the moment, my current idea is:

  • make a branch

  • take the remote into it,

  • 'git div master branch> my_patch'

  • apply this patch to a branch,

  • click from branch to remote control,

  • pull in the master

  • and kill the branch.)

Clearly, my idea is quite complex and ugly. Any ideas?

+5
source share
4 answers

Something like this (if you start with a lost moment.),

# Make the current directory a git repository.
# This puts you on a master branch with no commits.
git init

# Add a reference to the remote repository.
git remote add origin urlurlurl

# Fetch the remote refs.
git fetch

# Without touching the working tree, move master branch
# from nowhere onto the remote master.
git reset origin/master

# Stage all changes between the new index and the current tree.
git add -A

# Make a commit of these changes.
git commit -m "New working tree as a patch on remote master"
+9
source

I do not think that in your case it is necessary to create a new branch. Here is my answer: Do the following in your current local broken repo:

git init
git add .
git commit -m 'add files'  #create the local master branch
git remote add myproj [some_url]
git fetch myproj  
git branch -r  #check the remote branches
git diff master..myproj/master  #view the diffs between your local and remote repos
#now you are sure there is no conflict,
#so you merge the remote to your local master branch
git pull myproj master  
git push myproj  #push your local master branch to remote
#now your upstream and downstream is sync'ed
+3
source

(, , , git)

git clone -n [git_url] tmp_git_dir
mv tmp_git_dir/.git .
rm -rf tmp_git_dir
git add .
git commit -a -m "commit message"

. , .

I wonder if there is a way to clone the git repository into the current directory (basically, I just want the .git registry in place in the current directory, so I don't need to do mv and rm)?

+1
source

Sorry if I misunderstood you, but I think you just want to do a standard pull and push? Read about it . Git will handle any merges for you, and if there are conflicts, you can easily sort them.

0
source

All Articles