DEV Community

Cover image for Just Git like a pro

Just Git like a pro

Steve Yonkeu on February 27, 2024

In the ever-evolving world of software development, managing code changes is paramount. This is where Version Control Systems (VCS) come into play....
Collapse
 
pauljlucas profile image
Paul J. Lucas

Git provides features like:

The features you list are also provided by most other VCSs. You're making it seem like those features are unique to git β€” they're not.

You mention .gitignore, but you neglect to mention that you can also have .gitignore files on a per-project and per-directory-per-project basis.

You give global configuration for git, but you don't give any examples of actually using git to create a repo, clone a repo, branching, merging, etc.

Collapse
 
yokwejuste profile image
Steve Yonkeu

Right!
Git, as a Version Control System (VCS), uniquely offers a distributed architecture, enabling each user to have a complete local copy of the entire project history, providing robustness and flexibility in managing branches and merging changes. Its emphasis on non-linear development through thousands of parallel branches, powerful merge capabilities, and the ability to handle large projects with speed and efficiency set it apart. Additionally, Git's data integrity feature, where every file and commit is checksummed, ensures the integrity of the project history, making it distinct among VCS options.

Will do the necessary adjustments.

Collapse
 
pauljlucas profile image
Paul J. Lucas

Git, as a Version Control System (VCS), uniquely offers a distributed architecture, ...

No it doesn't. Mercurial is also distributed, so git can't uniquely offer a distributed architecture.

Thread Thread
 
yokwejuste profile image
Steve Yonkeu

Git uniquely offers a precise staging area, efficient DAG-based storage, powerful rebase feature, and a vast ecosystem of tools and integrations.

Thread Thread
 
pauljlucas profile image
Paul J. Lucas
  • You assume that a typical user knows what a "precise staging area" is.
  • Why should a user care that it uses DAG-based storage?
  • You assume that a typical user knows what a "rebase feature" is.

For all those points, you assume that a typical user knows why those things are "better." It would be like me saying "cars from Company X offer precise frabnoozles, efficient whozawhats, and a powerful gebholtz feature." Without knowing what those terms mean, the statement is meaningless. You need to explain what those git features are any why anybody should care.

Collapse
 
waterkip profile image
Wesley Schwengle

I don't like your multi-account setup if honest. It is a less-than-optimal solution.

Collapse
 
yokwejuste profile image
Steve Yonkeu

So what are your suggestions ?

Collapse
 
waterkip profile image
Wesley Schwengle

I think you should change core.sshCommand in your git projects. You can do this by organising your projects in such a way that you use an includeIf based on the gitdir you are in. If you want the specifics, see this blogpost

Thread Thread
 
yokwejuste profile image
Steve Yonkeu

So you mean setting up the configuration in such a way we use this command?

GIT_SSH_COMMAND="ssh -i ~/.ssh/id_rsa_example" git clone git@example.com:repo.git
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
waterkip profile image
Wesley Schwengle

Yes, you are going to configure the GIT_SSH_COMMAND in your git config and if you correctly organise your projects you can use any forge by selecting the correct ssh key and you can even, with a little shell script do it within repo's depending on the remote.

Thread Thread
 
yokwejuste profile image
Steve Yonkeu

Sounds interesting as suggestion, will be best to avoid looping through the existing keys trying to find one.

But if you look closely, you will notice there is a change in the origin I use to clone the repos.

Take for example, to clone a personal repo I'll do the following:

# the gitconfig to be used

# for personal user
Host github.me

  HostName github.com

  User yokwejuste

  IdentityFile ~/.ssh/personal
Enter fullscreen mode Exit fullscreen mode

Then upon cloning the repo, I'll use:

# using this
git clone git@github.me:unstructuredstudio/zubhub.git

#instead of this
git clone git@github.com:unstructuredstudio/zubhub.git
Enter fullscreen mode Exit fullscreen mode

Having a close look at the ssh url, we can see a change from .com => .me

Thread Thread
 
waterkip profile image
Wesley Schwengle

Yes, as mentioned, you would use: sshCommand = -i ~/.ssh/id_client -o IdentityOnly=yes -F /dev/null:

The identityOnly=yes is only there to prevent ssh from looping over all your ssh-keys and potentially using a different ssh key. The -F /dev/null disables using your .ssh/config. You could also use a different SSH config for just the sshCommand, e.g. sshCommand = -F ~/.ssh/config-client and set the correct ssh options in that file.

I know what you are saying, but the problem is that you now need to change all the hostnames when cloning other remotes, upstream, yours and others depending on the size of your (project) team.

Thread Thread
 
yokwejuste profile image
Steve Yonkeu

Inputing the ssh identity file can be more effective in terms of performance at the end.

Thanks again for this.

Collapse
 
fpaghar profile image
Fatemeh Paghar

he key advantages of utilizing a Distributed Version Control System (DVCS) like Git over a Centralized Version Control System (CVCS) like SVN are multifaceted. Firstly, DVCS allows each developer to have a complete copy of the project's repository, enabling them to work independently without constant reliance on a central server. This decentralization not only enhances flexibility but also mitigates the risk of a single point of failure, as seen in CVCS. Additionally, DVCS facilitates more streamlined collaboration by offering features like branching and merging, which are faster and more efficient compared to CVCS. Branching in Git, for instance, allows developers to create isolated environments for experimentation or feature development, which can later be merged back into the main codebase seamlessly. Moreover, DVCS promotes a more distributed workflow, making it easier for teams distributed across different locations to work together effectively. Overall, the distributed nature and robust feature set of DVCS like Git make it the preferred choice for modern software development projects over traditional centralized systems like SVN.

Collapse
 
mankavelda profile image
Manka Velda

Interesting πŸ‘πŸ‘©β€πŸ’»
I thought I knew git until this πŸ˜…
Thank u

Collapse
 
yokwejuste profile image
Steve Yonkeu

πŸ’‘ you're welcome

Collapse
 
jemendieta profile image
Jemendieta

Thank U

Collapse
 
yokwejuste profile image
Steve Yonkeu

You're welcome

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard • Edited

Git is the best because everyone else uses it.

On the merits, I'm not convinced. One of my most contentious hot takes here is that git is not the end of history

Git is very flexible but poorly optimized for the kind of workflow my team work on and thus has a big tendency to get in the way.

Collapse
 
mfalconi profile image
mfalconi

what does your team use for version control?

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard • Edited

We use git because that's what everyone (the colleagues, GitHub, the CI, ...) is using and there is lots of value in that.

On the other hand, I feel totally free to disregard so called "git best practices" whenever they don't serve us but instead slow us down. git is just a tool, not the actual work we are trying to do.

Collapse
 
disukharev profile image
Dima Sukharev

in case you want a tool to generate a commit message: dev.to/disukharev/opencommit-featu...

Some comments have been hidden by the post's author - find out more