How to remove files from git staging area?
2023-07-26
Question I made changes to some of my files in my local repo, and then I did git add -A which I think added too many files to the staging area. How can I delete all the files from the staging area? After I do that, I'll just manually do git add "filename". Answer You can unstage files from the index using git reset HEAD -- path/to/file Just like git add, you can unstage files recursively by directory and so forth, so to unstage everything at once, run this from the root directory of your repository:…
How to filter Pandas dataframe using 'in' and 'not in' like in SQL
2023-07-24
Question How can I achieve the equivalents of SQL's IN and NOT IN? I have a list with the required values. Here's the scenario: df = pd.DataFrame({'country': ['US', 'UK', 'Germany', 'China']}) countries_to_keep = ['UK', 'China'] pseudo-code: df[df[‘country’] not in countries_to_keep] My current way of doing this is as follows: df = pd.DataFrame({'country': ['US', 'UK', 'Germany', 'China']}) df2 = pd.DataFrame({'country': ['UK', 'China'], 'matched': True}) IN df.merge(df2, how=‘inner’, on=‘country’) NOT IN not_in = df.…
Pretty-print an entire Pandas Series / DataFrame
2023-07-24
Question I work with Series and DataFrames on the terminal a lot. The default __repr__ for a Series returns a reduced sample, with some head and tail values, but the rest missing. Is there a builtin way to pretty-print the entire Series / DataFrame? Ideally, it would support proper alignment, perhaps borders between columns, and maybe even color-coding for the different columns. Answer You can also use the option_context, with one or more options:…
How do I "git clone" a repo, including its submodules?
2023-07-20
Question How do I clone a git repository so that it also clones its submodules? Running git clone $REPO_URL merely creates empty submodule directories. Answer With version 2.13 of Git and later, --recurse-submodules can be used instead of --recursive: git clone --recurse-submodules -j8 git://github.com/foo/bar.git cd bar Editor’s note: -j8 is an optional performance optimization that became available in version 2.8, and fetches up to 8 submodules at a time in parallel — see man git-clone.…
Is there a way to cache https credentials for pushing commits?
2023-07-20
Question I recently switched to synchronizing my repositories to https:// on GitHub (due to firewall issues), and it asks for a password every time. Is there a way to cache the credentials, instead of authenticating every time that git push? Answer Since Git 1.7.9 (released 2012), there is a neat mechanism in Git to avoid having to type your password all the time for HTTP / HTTPS, called credential helpers.…
Git fast-forward VS no fast-forward merge
2023-07-18
Question Git merge allows us to perform fast-forward and no fast-forward branch merging. Any ideas when to use fast-forward merge and when to use no fast-forward merge? Answer The --no-ff option is useful when you want to have a clear notion of your feature branch. So even if in the meantime no commits were made, FF is possible - you still want sometimes to have each commit in the mainline correspond to one feature.…
Change Git repository directory location.
2023-07-17
Question With Git/Github for Windows, if I have a repository with this directory: C:\dir1\dir2, what do I need to do to move the repo files to C:\dir1? I can obviously physically copy and paste the files, but what do I need to do on the Git side? I have this repo on GitHub and I use Git Bash and GitHub for Windows. Answer Simply copy the entire working directory contents (including the hidden .…