How can I know if a branch has been already merged into master?
2023-05-16
Question I have a git repository with multiple branches. How can I know which branches are already merged into the master branch? Answer git branch --merged master lists branches merged into master git branch --merged lists branches merged into HEAD (i.e. tip of current branch) git branch --no-merged lists branches that have not been merged By default this applies to only the local branches. The -a flag will show both local and remote branches, and the -r flag shows only the remote branches.…
How to change folder with git bash?
2023-05-14
Question My default git folder is C:\Users\username\.git. What command should I use to go into C:/project? Answer The command is: cd /c/project/ Tip: Use the pwd command to see which path you are currently in, handy when you did a right-click "Git Bash here..."
Move existing, uncommitted work to a new branch in Git
2023-05-14
Question I started some work on a new feature and after coding for a bit, I decided this feature should be on its own branch. How do I move the existing uncommitted changes to a new branch and reset my current one? I want to reset my current branch while preserving existing work on the new feature. Answer Update 2020 / Git 2.23 Git 2.23 adds the new switch subcommand in an attempt to clear some of the confusion that comes from the overloaded usage of checkout (switching branches, restoring files, detaching HEAD, etc.…
Set up git to pull and push all branches
2023-05-14
Question I'd like to push and pull all the branches by default, including the newly created ones. Is there a setting that I can define for it? Otherwise, when I add a new branch, locally and I want to pull it from the server, what is the simplest way to do it? I created a new branch with the same name and tried to pull but it doesn't work. Asks me for all the remote config of the branch.…
Can't ignore UserInterfaceState.xcuserstate
2023-05-13
Question I'm using Git for Xcode 4 project version control. I've explicitly added ProjectFolder.xcodeproj/project.xcworkspace/xcuserdata/myUserName.xcuserdatad/UserInterfaceState.xcuserstate to .gitignore, but Git it won't ignore it. Any ideas why this is so? Answer Git is probably already tracking the file. From the gitignore docs: To stop tracking a file that is currently tracked, use git rm --cached. Use this, replacing [project] and [username] with your info: git rm --cached [project].xcodeproj/project.xcworkspace/xcuserdata/[username].xcuserdatad/UserInterfaceState.xcuserstate git commit -m "Removed file that shouldn't be tracked"…
Unstage a deleted file in git
2023-05-11
Question Usually, to discard changes to a file you would do: git checkout -- <file> What if the change I want to discard is deleting the file? The above line would give an error: error: pathspec '<file>' did not match any file(s) known to git. What command will restore that single file without undoing other changes? bonus point: Also, what if the change I want to discard is adding a file?…
Convert pandas dataframe to NumPy array
2023-05-10
Question How do I convert a pandas dataframe into a NumPy array? DataFrame: import numpy as np import pandas as pd index = [1, 2, 3, 4, 5, 6, 7] a = [np.nan, np.nan, np.nan, 0.1, 0.1, 0.1, 0.1] b = [0.2, np.nan, 0.2, 0.2, 0.2, np.nan, np.nan] c = [np.nan, 0.5, 0.5, np.nan, 0.5, 0.5, np.nan] df = pd.DataFrame({‘A’: a, ‘B’: b, ‘C’: c}, index=index) df = df.rename_axis(‘ID’) gives…