Change a branch name in a Git repo
2022-12-17
Question How do I rename an existing branch in a Git repo? I want the current branch to have a new name. Answer Assuming you're currently on the branch you want to rename: git branch -m newname This is documented in the manual for git-branch, which you can view using man git-branch or git help branch Specifically, the command is git branch (-m | -M) [<oldbranch>] <newbranch> where the parameters are:…
Meaning of Git checkout double dashes
2022-12-17
Question What is the meaning of the double dashes before the file name in this git command? git checkout --ours -- path/to/file.txt git checkout --theirs -- path/to/file.txt Are they mandatory? Is it equivalent to git checkout --ours path/to/file.txt git checkout --theirs path/to/file.txt Answer Suppose I have a file named path/to/file.txt in my Git repository, and I want to revert changes on it. git checkout path/to/file.txt Now suppose that the file is named master.…
How can I make git accept a self signed certificate?
2022-12-16
Question Using Git, is there a way to tell it to accept a self signed certificate? I am using an https server to host a git server but for now the certificate is self signed. When I try to create the repo there for the first time: git push origin master -f I get the error: error: Cannot access URL https://the server/git.aspx/PocketReferences/, return code 22 fatal: git-http-push failed Answer To permanently accept a specific certificate Try http.…
Skip Git commit hooks
2022-12-16
Question I'm looking at a Git hook which looks for print statements in Python code. If a print statement is found, it prevents the Git commit. I want to override this hook and I was told that there is a command to do so. I haven't been able to find it. Any thoughts? Answer Maybe (from git commit man page): git commit --no-verify -m "commit message" ^^^^^^^^^^^ -n --no-verify This option bypasses the pre-commit and commit-msg hooks.…
What effect does the `--no-ff` flag have for `git merge`?
2022-12-16
Question Using gitk log, I could not spot a difference between the effect of git merge and git merge --no-ff. How can I observe the difference (with a git command or some tool)? Answer The --no-ff flag prevents git merge from executing a "fast-forward" if it detects that your current HEAD is an ancestor of the commit you're trying to merge. A fast-forward is when, instead of constructing a merge commit, git just moves your branch pointer to point at the incoming commit.…
Difference between Git and GitHub
2022-12-15
Question I have recently added a new project to Git using Eclipse, but do not see the project appear in my GitHub account. Why do they have the same account information and different repositories? Isn't Git and GitHub the same thing? Answer Git is a revision control system, a tool to manage your source code history. GitHub is a hosting service for Git repositories. So they are not the same thing: Git is the tool, GitHub is the service for projects that use Git.…
Make .gitignore ignore everything except a few files
2022-12-15
Question I understand that a .gitignore file cloaks specified files from Git's version control. How do I tell .gitignore to ignore everything except the files I'm tracking with Git? Something like: # Ignore everything: * Do not ignore these files: script.pl template.latex Answer An optional prefix ! which negates the pattern; any matching file excluded by a previous pattern will become included again. If a negated pattern matches, this will override lower precedence patterns sources.…