General Flashcards
(32 cards)
what is origin?
origin is an alias on your system for a particular remote repository. It’s not actually a property of that repository.
By doing
git push origin branchname
you’re saying to push to the origin repository. There’s no requirement to name the remote repository origin: in fact the same repository could have a different alias for another developer.
Remotes are simply an alias that store the URL of repositories.
In the push command, you can use remotes or you can simply use a URL directly. An example that uses the URL:
git push git@github.com:git/git.git master
Remotes are simply an alias that store the URL of repositories. You can see what URL belongs to each remote by using
git remote -v
This alias name is not hard coded and could be changed using following command prompt:
git remote rename origin mynewalias
“detached HEAD” state
usually when you do git checkout, you check out a branch, not a commit
however, you can also say git checkout SHA1 has of a specific commit
git checkout a05eff1
The HEAD pointer in Git determines your current working revision (and thereby the files that are placed in your project’s working directory). Normally, when checking out a proper branch name, Git automatically moves the HEAD pointer along when you create a new commit. You are automatically on the newest commit of the chosen branch.
When you instead choose to check out a commit hash, Git won’t do this for you. The consequence is that when you make changes and commit them, these changes do NOT belong to any branch.
This means they can easily get lost once you check out a different revision or branch: not being recorded in the context of a branch, you lack the possibility to access that state easily
So if you want, say, to see an older version, you can check out this particular commit into a new branch and then make commits to this branch
git checkout -b test-branch 56a4e5c08
HEAD
Woher weiß Git, auf welchem Branch Sie gegenwärtig sind? Es besitzt einen speziellen Zeiger namens HEAD. Zeiger auf den aktuellen Commit des aktuell ausgecheckten Branches
Bei Git handelt es sich bei HEAD um einen Zeiger auf den lokalen Branch, auf dem Sie sich gegenwärtig befinden.
Let’s say we have master and anotherbranch with the same last commit. Current branch is master. So HEAD is pointing to the latest commit on master.
when we do git checkout anotherbranch, our HEAD switches to point to the commit of this another branch. At the moment, it is the same commit as that on master
Beim Commit wird der HEAD automatisch auf diesen neuen Commit nach vorne verschoben. So anotherbranch is now one commit ahead of master
if we do git checkout master again after that, the head will point again to the old commit which is the latest on master
https://git-scm.com/book/de/v2/Git-Branching-Branches-auf-einen-Blick
With the “git checkout” command,
you determine which revision of your project you want to work on. Git then places all of that revision’s files in your working copy folder.
if you have changed a file and want to restore it to the state it is in the index, don’t delete the file first, just do
git checkout – path/to/foo
If you would like to incorporate the changes you made in branch tmp into master
run git merge tmp from the master branch.
list all local branches
git branch
list all local and remote branches
git branch -a
list all remote branches
git branch -r
Merge into the current branch the remote branch next
git pull origin next
get remote branch master into your local repo, without pulling it into working space
git fetch origin master
Print all refs from remote (branches, tags, …):
git ls-remote origin
How can I tell a local branch to track a remote branch?
git branch -u origin/dev
In cases when you simply forgot, you can set (or change) a tracking relationship for your current HEAD branch at any time
show remote repo info and its branches
git remote show origin
check out and track remote branch
git checkout –track origin/dev
push your local branch that does not exist in remote yet to remote, to create there the counterpart
git push -u origin dev
remotes\origin\HEAD
indicates the default branch on the remote. The logic is that you can then use origin as a shorthand whenever you would otherwise use origin/master. E.g. it makes git log origin/master equivalent to git log origin.
what to do if git branch -a does not show all remote branches and any commands including some remote branches show errors that branch is not known
if git fetch –all does not help (it should load all remotes into the local repo):
- in the project check dir .git\refs\remotes\origin there must be files for each remote branch
- check git config (in the project!) for this line
fetch = +refs/heads/:refs/remotes/origin/ - to add this line to config run
git config remote.origin.fetch ‘+refs/heads/:refs/remotes/origin/’ - then again git fetch –all
- if this doesn’t work we need to remove remote completely from local computer. So run:
git remote remove origin
git remote add origin
git fetch origin
- then run git branch -a to check
remove local branch
git branch -d
Git will not let you delete the branch you are currently on so you must make sure to checkout a branch that you are NOT deleting.
The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn’t been pushed or merged yet.
to force deletion
git branch -D
rename local branch
git branch -m master tobedeleted
view hash of your current branch
git rev-parse HEAD
see git tree
git log –graph –decorate –oneline –all –full-history