Reputation: 33
In git I have a bitbucket remote setup and in local I have a new folder withfiles. How can I pull all the files in the remote to my local without deleting the files that arn't in the remote
Upvotes: 0
Views: 1698
Reputation: 4017
Scenario 1: These are un-tracked file
You can just pull
. None of your un-tracked files will be replaced
Git is a version control system. It keeps track of files you've asked it to track. So if you haven't set a file for git tracking it won't be replaced even if you git pull
from remote.
Here's a demo bash script that will actually recreate your scenario.
#!/bin/bash
#from your home (~/) directory
mkdir temp && cd temp
#Init a git bare repo (this is your remote)
git init --bare remote.git
#create local working tree 1 (this is user 1)
mkdir local_1 && cd local_1
git init
git remote add origin ~/temp/remote.git
touch file1
git add file1
git commit -m "first commit"
git push --set-upstream origin master
cd ..
# create local working tree 2 (this is user 2)
git clone remote.git
mv remote local_2 && cd local_2
touch file2
#make a new commit in local_1 and push it
cd ../local_1
touch file3
git add file3
git commit -m "second commit"
git push
#come back to local_2
cd ../local_2
#Pull and update your branch
git pull
#let's see if you still have file2 in your working tree.
ls file2
#yes you do!
After running this you can find that file2
still exist in your local_2
directory.
Scenario 2: These are tracked file.
A pull will result in a conflict if the files have changed. So you just have to do the work to merge them.
Upvotes: 1
Reputation: 1277
I almost never use git pull
and instead always use git fetch <remote>
(such as git fetch origin
). This fetches the files from your remote without modifying your local working files. You can then inspect further by doing something like:
git log --decorate --oneline --graph -20
I actually have that aliased as git tree
- you can set up the alias using:
git config alias.tree llog --decorate --oneline --graph -20'
Once you fetch the files using git fetch <remote>
you'll be able to look at them using the git tree
alias I provided or by checking out a remote branch.
Upvotes: 0