Git – Good to know

In this post i’d like to note some handy tricks when using git.

Good to know:

  • git commit –amend = replace (add to) last commit
  • git remote add <alias> <URL> = connect remote repository
  • git push origin/<branch> = upload changes to remote repository
  • git restore – use this command to undo local changes and replace the file with the one in the repository. see fryboyter.de
  • git checkout -b <branch> = create a branch and go there

4 ways to remove files from the repository:

  • git restore –staged datei.txt = remove from staging, keep in working-dir
  • git reset HEAD — datei.txt = replace staging with latest commit
  • git rm –cached datei.txt = don’t track file anymore, but keep local
  • git rm datei.txt = delete file – beware, it’s gone!

Clone a remote repository to local
git clone https://address/repository.git
git-scm.com – Git-Basics-Getting-a-Git-Repository

Useful Links:
git-scm.com Book

FAQ:
1) Error-message on git push: “fatal: The current branch branch-name has no upstream branch”
Solution: git push origin HEAD:branch_name
see: stackoverflow

2) Set branch new master:
https://stackoverflow.com/questions/2763006/make-the-current-git-branch-a-master-branch

> git checkout better_branch
> git merge –strategy=ours master # keep the content of this branch, but record a merge
> git checkout master
> git merge better_branch # fast-forward master up to the merge

3) error: failed to push some refs to repository
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., ‘git pull …’) before pushing again.

> git push -f

or:
> git pull –rebase origin main
> git push origin main
see: https://stackoverflow.com/questions/24114676/git-error-failed-to-push-some-refs-to-remote

You may also like...

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.