/r/git

Photograph via snooOG

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Git is not the same as GitHub. GitHub did not create Git. For GitHub-specific posts, please see /r/github.

Git is not an acronym or initialism: please write git or Git, but not GIT.


Documentation


Graphical Clients


Code Hosting

/r/git

69,856 Subscribers

16

Share your best git alias you made.

These are mine:

cleanup = "!git branch --merged | grep -Ev '(^\\*|master|main|dev)' | xargs git branch -d && echo 'Merged Branches cleaned ✨'"

remote-cleanup = "!git branch -r --merged | grep -Ev '(^\\*|master|main|dev)' | xargs -n 1 git push --delete origin && echo 'Merged Remote Branches cleaned ✨'"

undo = reset --soft HEAD~1

redo = reset --hard HEAD@{1}

6 Comments
2024/04/20
16:57 UTC

0

Cancel a change on my fork

Hi!

I just made a local commit on my fork of a GitHub project and... I did it in the main branch, and I didn't want to.

Since I have to create more branches later, is there a way to cancel this commit via github.com?

I could do another commit to undo it but... well, it will create a false history then.

Does anyone know how I can? Thanks in advance!

5 Comments
2024/04/20
12:58 UTC

1

I made a mess and cant find all my files locally

Long story short but I wanted to download part of my repo into another part of my repo, which I have historically done using the below code:

but now all my local files are gone - how on earth do I get them back? I cant still see them on github

git clone --filter=blob:none --no-checkout git@github.com:XXX/XXXX.git

git sparse-checkout set --cone
cd "X:/path/"
7 Comments
2024/04/20
09:36 UTC

1

How to handle old/new mode diff problem in public repositories?

I am maintainer of a public repository and sometimes experience problems like this when I clone a forked repo from a contributor.

diff --git a/update_language_files.py b/update_language_files.py
old mode 100755
new mode 100644

I sligthly know why this happens. But I am not sure how to handle that in a public repo. The information if a file is executable or not should be part of the repo.

These are my current settings:

global	file:/home/user/.gitconfig	core.filemode=false
local	file:.git/config	core.filemode=true

To my understanding when setting core.filemode to false will ignore the filemode when doing commit and diffs. That is not what I want. But as you can see the filemode in the repo (local setting scopeistrue`.

So why is the filemode modified when an extern contributor fork the repo and then I clone his fork? It happens several times so I can be sure that the contributors do not explicite modify the file permissions and there execution state.

I am confused about why this happens and how to solve it.

5 Comments
2024/04/20
08:51 UTC

0

Mastering Git and Github: Essential Information (Part 1)

Being in the field of software engineering git and github are the most well known tool and most useful tool for the developers. So here I have written a blog about git and github on Hashnode, reading blogs and articles can enhance and elevate your skills, so read the blog, Comment your opinion on that. Every comments are appreciated.

link : https://persevere08.hashnode.dev/git-github-all-you-need-to-know-part-1

2 Comments
2024/04/20
03:14 UTC

0

Mastering Git and Github: Essential Information (Part 2)

🚀 Excited to Share: Mastering Git Essentials! 🚀

Hey LinkedIn Fam,

I'm thrilled to share my latest blog post on Hashnode where I dive deep into mastering the essentials of Git. If you're looking to level up your version control game, this one's for you!

In the blog, I cover fundamental Git commands like:

🔹 git config: Setting up your Git environment just the way you like it.

🔹 git init: Initializing a new Git repository in your project folder.

🔹 git add: Staging changes for the next commit like a pro.

🔹 git status: Your trusty sidekick for keeping tabs on your project's status.

🔹 git commit: Capturing snapshots of your work with clear and concise commit messages.

Understanding these commands is key to mastering Git and enhancing your workflow as a developer. Whether you're just starting out or looking to refine your skills, this blog will guide you through the essentials with clarity and simplicity.

Ready to unlock the power of Git and take control of your projects? Check out the full blog post on #Hashnode, and let's embark on this journey of continuous improvement together! Don't forget to leave your thoughts and questions in the comments – I'd love to hear from you.

Happy coding! 🚀✨

Soumya Dey https://persevere08.hashnode.dev/mastering-git-and-github-essential-information-part-2

0 Comments
2024/04/20
03:09 UTC

3

Learning Git: A Hands-On & Visual Guide • Anna Skoulikari & Helen Scott • GOTO 2024

0 Comments
2024/04/19
05:13 UTC

0

help me-how to roll back to older version of my code, and push back that old code to my 'main'.

cause i wanna my old version back to my public git

-i did git checkout but not help

**some people mention me that i need
create branch version number and then any features are commits
example:

git checkout -b <newBranchName>
git push origin <newBranchName>

idk what to do next.. ?

3 Comments
2024/04/18
21:48 UTC

1

Can the git clone -c flag be used with submodules?

I have a case where I would like to apply a -c setting to all of the submodules brought in by 'git clone --recursive ...' (in this case it's 'core.autocrlf=false').

This setting is correctly applied to the parent repo's config file but does not appear in the submodules. Can this be done in one clone command? If not what's the best way to apply this to all present submodules?
Edit: On Windows if it matters-

2 Comments
2024/04/18
13:20 UTC

1

git p4 clone error

I'm using "git p4 clone" to convert a large (50 gb) repository from perforce to git.

I'm getting an error message I don't understand. Any pointers?

​

$ git p4 clone "//depot/project/1.0"@all

Reinitialized existing Git repository in D:/github/tmp/1.0/.git/

Importing from //depot/project/1.0@all into 1.0

Import destination: refs/remotes/p4/master

Importing revision 10400 (100%)fast-import failed: b"warning: Not updating refs/remotes/p4/master (new tip 55555fbcd91de522da4824266fb29f9951758fa1 does not contain 99a8bf362ac3d92cc7e54ca9712adef7efff94af)\nfast-import statistics:\n---------------------------------------------------------------------\nAlloc'd objects: 55000\nTotal objects: 50079 ( 7695 duplicates )\n blobs : 44638 ( 7284 duplicates 26441 deltas of 44287 attempts)\n trees : 5436 ( 411 duplicates 36 deltas of 39 attempts)\n commits: 5 ( 0 duplicates 0 deltas of 0 attempts)\n tags : 0 ( 0 duplicates 0 deltas of 0 attempts)\nTotal branches: 1 ( 1 loads )\n marks: 1048576 ( 5 unique )\n atoms: 40240\nMemory total: 13400 KiB\n pools: 9533 KiB\n objects: 3867 KiB\n---------------------------------------------------------------------\npack_report: getpagesize() = 65536\npack_report: core.packedGitWindowSize = 1073741824\npack_report: core.packedGitLimit = 35184372088832\npack_report: pack_used_ctr = 91\npack_report: pack_mmap_calls = 3\npack_report: pack_open_windows = 3 / 3\npack_report: pack_mapped = 1120443146 / 1120443146\n---------------------------------------------------------------------\n\n"

​

1 Comment
2024/04/17
19:21 UTC

8

Are there any tools for visualizing a git repository?

I'm working on a project together with my team, and we're going to have to present the product in some time; I was wondering if there are any tools that can visualize a git repository. In a sense probably closer to something up /r/dataisbeautiful's alley, rather than something like UML.

I know of Gource, and we are going to be using it, along with commentary on the side so these "non-techies" can understand it better.

Specifically, I was looking for something like GitHub Insights. I know there are some, I came across a few years ago, but having been looking through various threads, the most I find are just Gource, UML-related or GitHub's profiles "Your Contributions" section. Which probably just speaks to my deteriorating ability to search in today's landscape lol, but I digress.

The reason why I'm looking for other visualization tools is mostly because the graphs on the GitHub repo do not seem to add up. For example, in a repository with well above 600 commits, the graphs show just above 400. And while lines added or deleted aren't a useful indicator for real work done, but they're something to look at while that is explained.

Also, apologies if this is the wrong place to ask.

e: Of course, as par the course, I found a website describing some solutions immediately after posting. Welp. Sucks to suck, I guess. I'd still appreciate any pointers to software, though; there may be gems I simply do not know of yet, after all.

2 Comments
2024/04/17
19:03 UTC

5

Cherry-pick behaviour

Let's say I have a repo that looks like this:

repo
  |- .git
  |- file

The content of file at the main branch:

a
b
c
d
e

Then I do the following:

> git checkout -b feature

# after editing the second line

> cat file
a
x
c
d
e

> git commit -am "Change second line to x"

# after editing the fourth line

> cat file
a
x
c
x
e

> git commit -am "Change fourth line to x"

# after editing the fifth line

> cat file
a
x
c
x
f

> git commit -am "Change fifth line to f"

> git checkout main

> git cherry-pick feature
Auto-merging file
CONFLICT (content): Merge conflict in file
error: could not apply 1d17197... Change fifth line to f
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".

> cat file
a
b
c
<<<<<<< HEAD
d
e
=======
x
f
>>>>>>> 1d17197 (Change fifth line to f)

How come git thinks there's also a conflict on the fourth line even though feature points to the commit that changes the fifth line only?

4 Comments
2024/04/17
10:34 UTC

2

prevent push and force push locally

Hey everyone, is there a way to configure your git to prevent pushing to certain branches (like main for instance) locally ?

For example when you are on a team that doesn't want to prevent this in the repo settings you could just do it for yourself at least

​

I don't think you can but thanks a lot for your time

9 Comments
2024/04/17
09:50 UTC

1

How to bring back Credential Helper Selector popup?

0 Comments
2024/04/17
04:10 UTC

1

OpenSSH authentication still popping up. I want to use Https

Hello, I'm on a work laptop trying to learn git in a class.

The whole class had issues with git push, which we now believe was just some permissions issue our IT team had to fix.

While I was trying to solve that, I tried using SSH to get by.. well now when I try it again to keep up with the class and OpenSSH window pops up asking for my credentials.

If I do git remote -v it has Https though.

Any idea?

1 Comment
2024/04/17
00:53 UTC

0

How can I commit and push another folder/directory to the same repo?

Hi everyone, I want to replace the current files and folders on my github repository because I forked an existing repo but then I decided to restart the project from scratch, but I don't know how to do it.

Creating a new repo is the last thing I want to do, but I'll do it if there is no other way.

​

Thanks again!

6 Comments
2024/04/16
19:43 UTC

0

Vite + React App

I published a vite + react application using gh-pages and it worked, but when i go to the page its a all white webpage. https://moe-9999.github.io/ReactMassageWebsite/

​

4 Comments
2024/04/16
19:07 UTC

1

Storing signing key in .gitconfig

I am moving all of my dotfiles into a git repo, including my .gitconfig. However I have found a field called signingkey with an ssh-rsa key in it. I think this is a private key, but I am not sure how I should actually store it, except I know that it should not be checked in. How should I store it?

[user]
	name = <NAME>
	email = <EMAIL>
	signingkey = ssh-rsa <KEY>
[gpg]
	format = ssh
[gpg "ssh"]
	program = /Applications/1Password.app/Contents/MacOS/op-ssh-sign
3 Comments
2024/04/16
16:14 UTC

2

Shallow/partial clone since a given commit or time stamp

shallow-clone, as I understand, allows to specify a number of commits to clone, most recent first.

What I'm looking for is to have the recent history up to a given commit (or maybe time stamp). Can be limited to a branch, but needs to include merged branches.

Is that even possible?

3 Comments
2024/04/16
10:29 UTC

0

Newbie git issue

Hello all. I'm trying to learn git, and today I got some very weird and unexpected behavior.

In my repo, I have a main branch, a dev branch branched off of main. Yesterday, I created a branch xdev, branched off of dev. I have remote branches on github corresponding to main and dev, but not to xdev.

I never staged or committed changes on xdev. However, today I was able to switch to dev, but the workspace didn't update. Then, I made a random change in dev, switched to xdev, and the workspace didn't update again. Then, I made another change in xdev, switched to dev, and the worskpace didn't update.

That is, the workspace seems to be completely independent from the branches. In the terminal it says "switched to branch X", but the workspace itself isn't actually changing with the branch.

However, if I try to change from dev to main, or from xdev to main, I get the expected message that I need to commit the changes before switching.

I would appreciate any help in understanding this.

If it's relevant, I am using VS Code on Ubuntu, and I have the GitLens - Git supercharged extension.

5 Comments
2024/04/16
04:02 UTC

1

New Git Visualization Tool

A while back I started working on a tool to visualize a Git repo and posted about it here. It didn't really work and wasn't well thought out. As I'm currently learning Go, I figured I'd try to write a better version of this. Learn Go and hopefully provide a better Git learning tool for beginners or experts alike. Here's what I got thus far. Everything is bundled in a binary which is neat too.

video example: https://youtu.be/UVZydtLrPtc?si=nf-rAzFcDQXpBihx

repo: https://github.com/jdoiro3/DaGit

1 Comment
2024/04/15
21:42 UTC

0

Newbie question on line ending

Hey there super new to this bear with me, I read some stack overflows and a few posts here and still have a few questions.

So I work alone on both a Windows and Mac machine back and forth. In regards to line endings would setting config autocrlf-input on both machines and EOL=lf in VScode be sufficient to take care of maintaining lf endings in the remote and when pulling onto my windows machine/ making new files?

If I understand it correctly new files in VScode should be lf ending, when pushed to the remote from the windows machine they should be converted to lf and when pulled onto the windows machine they should be lf ?

My only concern is in regards to binary files (jpgs pngs etc)

And I read something somewhere can't find the link about dockerized files and converting back and forth ( which this hopefully avoids?)

It would be nice to also avoid it showing as every line modified if that's a side effect of this but I understand if that's acting a lot.

Apologize for the length and any over simplification and appreciate any help in advance.

Thanks !

5 Comments
2024/04/15
08:24 UTC

2

Unchanged zip file considered modified

Hey, why is it that when I delete and re-create a zip file with the same name and same contents, git thinks it is modified? The intent is that it should not consider it "modified". If anyone else has seen this, I would like to know what you did to get around it. Thanks!

I re-created the scenario here. Everything after "$" is the command I ran on the terminal and the output following it is below it. (removed the output of git init though)

$ git init
$ echo "f1" > f1
$ echo "f2" > f2

$ ls
f1  f2

$ zip f.zip f1 f2
  adding: f1 (stored 0%)
  adding: f2 (stored 0%)

$ ls
f.zip  f1  f2

$ git add .
$ git commit -m "f1 & f2"
[master (root-commit) f6f15ed] f1 & f2
 3 files changed, 2 insertions(+)
 create mode 100644 f.zip
 create mode 100644 f1
 create mode 100644 f2

$ ls
f.zip  f1  f2

$ git status
On branch master
nothing to commit, working tree clean

$ rm f.zip
$ ls
f1  f2

$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    f.zip

no changes added to commit (use "git add" and/or "git commit -a")

$ zip f.zip f1 f2
  adding: f1 (stored 0%)
  adding: f2 (stored 0%)

$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   f.zip

no changes added to commit (use "git add" and/or "git commit -a")

If it is important, I am running this on Ubuntu WSL and my git version is 2.34.1

11 Comments
2024/04/15
02:47 UTC

1

What is the right approach for moving repos with large binary assets from perforce to github?

I have about a dozen large repositories in a perforce server that I need to move to github. The repos include code and assets with each repo having around ten thousand files and the assets averaging probably 10 gb per repo.

I've used "p4 git clone" to create local git repos. Everything looks good. I now want to push these repos to github.

But, before I do that, it seems like I shouldn't just push the repos to github without dealing with the binary files first. Ok, but how can I set up git lfs on my local repo? What is the right approach here? What will github do if I just push the repos as is?

I suppose I don't HAVE to have version history on the binary files if it is too complicated.

5 Comments
2024/04/14
03:38 UTC

0

Connection to GitHub slow over ethernet

2 Comments
2024/04/13
20:32 UTC

Back To Top