Essentially, Git keeps tabs on text changes, but the definition is a version control system. Chances are you've already used git one way or another...
For further actions, you may consider blocking this person and/or reporting abuse
As a beginner got to know a lot because of this, I would like to add one more to it
git rm --cached filename
it removes files from your repo but still is available locally.Thank you for the addition!
this command removes file from your staging area but not locally
It removes files from from staging/index only
I think it wont remove from remote repo but staging area.
Git
rm
is the exact opposite ofadd
.So if you *add*ed files and then called
git rm --cached smth
it will remove that something from the staged changes. If you didn't change or add anything since the last commit, callinggit rm
will create this change (as if you would delete the file), staging it for your next commit.I tried
git merge -X theirs hello.txt
and received the messagemerge: hello.txt - not something we can merge
Have you encountered this?Try
git merge -X theirs dev
instead.I apologise for this mistake, git merge requires a branch name, of course, not the file name. I've corrected that in the article, thank you!
thanks!
Thank for this amazing article, could you please help me with one more issue.
How do I add changes made after a commit to the last commit. For example, I just created a nav menu and committed, after which I made a small change which I don't want to commit on its own but to add to the last commit.
Hope you understand and thank you in advance.
Sure thing! Firstly, you add the changes with
git add
, then change the last commit withgit commit --amend
.If you pushed your commit to the remote repository to push this change you'll need to use
git push --force
.Does it matter if branch changes are pushed to a remote before rebasing? Would the steps be any different?
No, the steps would be the same, but force push would wipe remote branch commits that have not been pulled and may require hard reset on all local repositories, apart from your own.
I don't think I 100% follow.
If I created a branch
git checkout -b my-new-branch
and then stage, commit, and push:git add .
git commit -m "my message"
git push origin my-new-branch
Does it matter that it the code was pushed to the remote? Could I then rebase as you described?
Yes you can rebase my-new-branch from main with
git rebase main
locally, but you will need togit push --force
my-new-branch to push these changes to a remote originThanks for the clarification. I think I understand. My plan at the moment is to try it with different scenarios and make sure I really do get it.
Great guide. Very much appreciated!
Great Article @valeriavg , helpful for those, whose beginning with Git.
Thank you, Your way is very useful, could you do another one for mid and advanced levels please
There's a very good book that covers git in depth should you seek more knowledge on the subject.
Thank you for your input, much appreciated
How are you being compatible with GitHub by changing the default branch name? It's completely unnecessary. If you're using "master" as the default branch name, GitHub will still let you use it as the default branch name.
When you create a repository on GitHub the default branch is main. It's not prohibited to use master as a default branch, but that would require a bit of a setup on GitHub to change the default name. Now I personally don't have a preference on how the branch is going to be called, but if a service, that I rely on a daily basis, asks me to do a one tiny naming change I prefer to comply out of respect.
I got to the part of remote repository, made an example repository in github and tried the commands above and get a RSA key fingerprint "not known by any other names". I try to continue and get permission denied (publickey). Ideas?
Try this solution from stack overflow: stackoverflow.com/questions/956089...
Great article! Well done!
Here is also a free open-source eBook on how to get started with Git that might be helpful for some people:
bobbyiliev / introduction-to-git-and-github-ebook
Free Introduction to Git and GitHub eBook
This is an open-source introduction to Git and GitHub guide that will help you learn the basics of version control and start using Git for your SysOps, DevOps, and Dev projects. No matter if you are a DevOps/SysOps engineer, developer, or just a Linux enthusiast, you can use Git to track your code changes and collaborate with other members of your team or open source maintainers.
The guide is suitable for anyone working as a developer, system administrator, or a DevOps engineer and wants to learn the basics of Git, GitHub and version control in general.
To download a copy of the ebook use one of the following links:
Dark mode
Light mode
After read this, I am a git master now! 😎
Very useful
Very helpful article! Thanks for sharing
Great article, and I hope people will try all the commands out and spend more than 7 minutes in practicing these 🙂
Great article!
thank you for sharing
Thanks for a marvelous Git tutorial.
If you using latest version of git then use:
git config --global init.defaultBranch main
I had to use "git config ––global init.defaultBranch main" to configure my git, the syntax using "=" isn't accepted with git 2.30.2.
Thank you, I'll update the article to reflect this
Dear Valeria,may I translate your all dev articles into Chinese?I would like to share it with more developers in China. I will give the original author and original source.
Yes, you have my permission to translate my articles to Chinese and publish them on a medium of your choice, provided you mention the original article source and author.
P.S. I'm flattered :-)