How do I fetch only one branch of a remote Git repository?
2023-07-30
Question I'd like to grab a single branch (not all of them) of a remote repository and create a local tracking branch that can track further updates to that remote branch. The other branches in the remote repository are very big, so I'd like to avoid fetching them. How do I do this? Answer git fetch <remote_name> <branch_name> Worked for me.
How to get the changes on a branch in Git
2023-07-30
Question What is the best way to get a log of commits on a branch since the time it was branched from the current branch? My solution so far is: git log $(git merge-base HEAD branch)..branch The documentation for git-diff indicates that git diff A...B is equivalent to git diff $(git-merge-base A B) B. On the other hand, the documentation for git-rev-parse indicates that r1...r2 is defined as r1 r2 --not $(git merge-base --all r1 r2).…
fatal: Not a git repository (or any of the parent directories): .git [duplicate]
2023-07-29
Question This question already has answers here: </div> fatal: Not a git repository (or any of the parent directories): .git (9 answers) Receiving "fatal: Not a git repository" when attempting to remote add a Git repo (38 answers) Closed 9 years ago. When I tried to push an existing repository on github.com, and it when I entered the command the website prompted me to put into the terminal, I got this error message fatal: Not a git repository (or any of the parent directories): .…
How do I provide a username and password when running "git clone git@remote.git"?
2023-07-28
Question I know how to include a username and password in a https Git URL like this: git clone https://username:password@host But I'd like to know how to provide a username and password to an SSH remote like this: git clone git@host.git I've tried like this: git clone username:password@git@host.git git clone git@username:password@host.git git clone git@host.git@username:password But they haven't worked. Answer Based on Michael Scharf's comment: You can leave out the password so that it won't be logged in your Bash history file:…
Is it possible to have different Git configuration for different projects?
2023-07-28
Question .gitconfig is usually stored in the user.home directory. I use a different identity to work on projects for Company A and something else for Company B (primarily the name / email). How can I have two different Git configurations so that my check-ins don't go with the name / email? Answer As of git version 2.13, git supports conditional configuration includes. In this example we clone Company A's repos in ~/company_a directory, and Company B's repos in ~/company_b.…
Hard reset of a single file
2023-07-27
Question How do I discard the changes to a single file and overwrite it with a fresh HEAD copy? I want to do git reset --hard to only a single file. Answer To reset both the working copy of my-file.txt and its state in the Git index to that of HEAD: git checkout HEAD -- my-file.txt -- means "treat every argument after this point as a filename". More details in this answer.…
How can I see the size of a GitHub repository before cloning it?
2023-07-26
Question Is there a way to see how big a Git repository is on GitHub before you decide to clone it? This seems like a really obvious/basic statistic, but I can't find how to see it on GitHub at all. Answer There's a way to access this information through the GitHub API. Syntax: GET /repos/:user/:repo Example: https://api.github.com/repos/git/git When retrieving information about a repository, a property named size is valued with the size of the whole repository (including all of its history), in kilobytes.…