How to update personal cloned github? - python

I recently downloaded an open-source project from github into my server using
$ git clone www.github.com/project_url
Then I added comments and descriptions inside the multiple files here and there.
When I went to the github repository of the original project github page,
many of the files were updated. But I'm hesitating to clone again because I think it would just overwrite every local files to which I wrote many of the comments.
Is there anyway I can download up-to-date files in the github,
but leave the comments that I added not being removed at the same time?

There are multiple strategies to go around this problem. A strategy is already explained. Another could be
Commit your changes (git commit -am <message>)
Do a git pull (git pull -r)
Resolve conflicts if any
Also, you can keep your changes separate in a separate branch. Here is what else can be done:
Create a separate branch in your local repository (git checkout -b <branch-name>, eg. git checkout -b new-branch)
commit changes in that new branch (git commit -am <message>)
Either you can merge now from your new branch to the old branch
git checkout old-branch; git merge new-branch.
resolve conflicts if any
OR
Raise a Pull Request after resolving any conflicts if any

You can use git stash for this. This will store everything you changed locally. Then you pull the changes from the original repository and then with 'git stash pop' your local changes will come back.
git stash
git pull
git stash pop
Conflicts can come up and need to be resolved.

Related

GitPython Read a branch without it existing locally or cloning

I'm trying to read a branch from a Git repository without having a local copy or cloning the repo.
The GitPython API seems to assume a repo either exists locally or you with to clone it to read it.
All i'd like to do is access all the commits from a branch, for a repo, without it existing locally.
I'm after something like this:
branch = git.Repo(https://github.com/MyOrg/MyRepo, 'master')
for commit in branch.commits:
print(commit)
I'm looking at the API and I just don't see anything like this.
Is this possible?

Git Pycharm change only the local master branch to be exactly like origin master branch

I have 2 local branches: "master" and "fix".
I also have an origin remote repo with a master branch that is different from my local master branch.
the "fix" branch used to be a copy of the master branch, but then I made a lot of changes:
I changed some of the files, renamed others, added new ones and deleted some.
now, I want my local master branch to be the same as the remote master branch - without changing the "fix" branch!
when I use git pull it does not pull all of the files from the remote repository. I am not sure why.
when I use git reset --hard origin/master, it does make the local master the same as the remote one - which is what I wanted - but it also adds files to the "fix" branch!
why does this heepens?
how can I do this without the "fix" branch changing?
You need to commit your changes to the fix branch before switching to the master branch
#current branch: fix
git add .
git status # to verify that every thing is ready to be committed
git commit -m "your commit message"
git checkout master
# current branch: master
git status # to verify if you have commits that weren't yet pushed
git pull # add --rebase option if you have some commits not yet pushed to avoid adding merge commit
I hope it helps :)

Using ac2git followed by bitbucket

I am using ac2git to convert my accurev depot to git repository. I am able to successfully make the conversion however when I follow the steps after creating the new repository I am unable to push the changes representing the accurev transactions that are now commits.
What I mean is I loose the history, I am only able to see the hist and the diff files when I check the commit options on bitbucket.
I followed the following steps:
python ac2git.py
cd existing-project
git add --all
git commit -m "Initial Commit"
git remote add origin http://****#bitbucket.******.git
git push -u origin master
I am new to bitbucket so I am not sure what the problem is? Has anyone tried this accurev->git->bitbucket before?
In other words, how do I move my git repository on my local created as a result of ac2git to a new repository on bitbucket ?
Your first step is to create a repository in BitBucket. Then you simply need to follow BitBucket's instructions:
cd /path/to/my/repo
git remote add origin http://****#bitbucket.******.git
git push -u origin --all # pushes up the repo and its refs for the first time
git push origin --tags # pushes up any tags
I'm not 100% certain that this is what has happened but it is worth noting that the ac2git script stores a lot of metadata under refs/ac2git/* refs, including a refs that will store a hist.xml, streams.xml and diff.xml in their commit history for each of your stream's transactions. See how_it_works.md which explains about refs/ac2git/depots/<depot_number>/streams/<stream_number>/info.
Though this ref acts as a branch, it shouldn't have been pushed up by invoking git push origin -u -all since the documentation claims that this only pushes things under refs/heads/. However, in case of errors the script may not correctly checkout a branch that was converted and it may leave your local repository in a detached HEAD state where it will have actually checked out one of the internal refs.
I don't know what a git push origin -u --all would do in this case for a brand new Bitbucket repo but if it had pushed your HEAD ref up to the repo then you would get this metadata on the remote.
However, for now this is just a theory and hopefully someone will be able to use this information to piece together a more clear solution for you.

Git pull failed to my web server

Locally (Cloud9), I have commited my changes to my repo (https://github.com/edward408/my-first-blog), however when i perform a git pull on my deployment server (PythonAnywhere) i get the following error:
Updating aef1181..5d68bfa
error: Your local changes to the following files would be overwritten by merge:
db.sqlite3
Please, commit your changes or stash them before you can merge.
Aborting
I have pushed the changes from my local console (Cloud9) and made sure by veryfing git status afterwards. It seems that the best path long-term is to updatede git on PythonAnywhere while updating it from my local git at the same time. However, how would I implement that without starting a new repo again? Id prefer not to change anything that I already have on PythonAnywhere.
Anywho, what would the best feasible solution at this point in time?
EDITED: Its not completely the same as the suggested link. I already have my local dev environment pushing updates to the project repo. To use git stash on PythonAnywhere, i would have to push from there as well. Unless this means executing stash locally?
All that means is db.sqlite3 has been modified on your production server. Because of this, git isn't sure whether it is ok to overwrite it with your new code (because that file is present in your repo). Really, you should just add that file to your .gitignore, but you can get around it with (on your production server) running:
git stash
# do your pull
git stash pop
Basically, stash "saves" modified files that haven't been committed and allows you to later restore it by popping it off again, after the merge has overwritten it. https://git-scm.com/book/en/v1/Git-Tools-Stashing

How to use a pull request in my local copy of a Git branch?

I'm not familiar with Git, I only know how to download a master or dev branch of a python software project from Github and install into my system (I do not really use Git locally).
Now there is a "pull request" by a GitHub user which contains a feature I find useful but not in the main or dev branch. How can I use that in my local copy?
And if I manage to include it into my local copy, would it be lost if I later updated to the latest maaster/dev branch?
see: Git fetch remote branch
git fetch
git checkout <the name of the remote branch>
You can revert to any commit anytime you want, those changes are kept in the repository so you can visit different versions of it during the development on all branches. You need to do a merge command, which if, there's not any conflict with the patch contained in the pull request, will combine the code of the patch with the code of the repository. If there's conflicting code, like shared files for example, you will have to do the proper refactors and select which changes get inside or not.
Here you have basic information about merging different branches:
http://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
Updating will only do a merge with the changes and your master. If you break something you can stash the changes and get to the original state.
Also I would suggest to checkout a fresh branch and apply that feature on the freshly created branch. If every thing works fine merge it to your master otherwise delete and forget it :P
if you dont know the branch name
use git fetch first to know the branch name
and then git checkout
Also maybe you can find this link useful

Categories

Resources