When I left the SVN world, I started to brave the new world of git. Not that new… the matter is that most system had already automated git basic usages until something weird happens during your commit/push process such as conflicts.
So, let’s start from scratch:
First commit
Approach 1 via HTTPS: Create the repo in Bitbucket or your Git tool and clone it. Note that it will create a folder. Make sure to copy the content in oyur actual working folder
If under Windows, I recommend using https://git-scm.com/download/win and using the console by clicking the mouse’s right button and git-> bash here from the directory where you want to create your project.
git clone https://user@bitbucket.org/projects/project.782.git
git add –all
git commit -am “<commit message>”
git push
or git push -f or git push -f <remote> <branch> that means
git push -f origin master
or safer: git push <remote> <branch> –force-with-lease
List ignored files
$ git ls-files . –ignored –exclude-standard –others
List untracked files
$ git ls-files . –exclude-standard –others
Git -Managing branches
Available local branches
git branch -a
Available remote branches
git branch -r
Other ways to check: git remote and git ls-remote
https://www.digitalocean.com/community/tutorials/how-to-use-git-branches
Git – Delete branch
https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-both-locally-and-remotely
Remote (this will not ask if you have merged something or not!):
git push <remote_name> –delete <branch_name>
Local:
git branch -d branch_name
git branch -D branch_name <– this delete regardless of already being merged
GIT checking / setting the current user and remote origin
git config user.name
git config –list
git config –global user.name “Alvin J. Alexander”
git config remote.origin.url user@email.com:repository/project.git (e.g. the address beside SSH word at Bitbucket).
You could still change it to https if you do not have an SSH key. In this case, it will be
https://user@email.com/repository/project.git
Git – returning 1 or more commits
For git – Your branch is ahead of ‘origin/master’ by 1 commit
git reset HEAD^ –soft (Save your changes, back to last commit in HEAD)
git reset HEAD^ –hard (Discard changes, back to last commit in HEAD)
Go back one commit
git push -f origin <last_known_good_commit>:<branch_name>
git reset –hard <last_known_good_commit>
# ^^^^^^
# optional (and dangerous. Will erase existing not mapped or updated files)
revert the last commit – git revert commit_number
Git Rebase
Jenkins – dealing with credentials (more on the Jenkins post)
Jenkins – accessing github.com , bitbucket.com …
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
For adding the key at Bitbucket side:
ssh-keygen -t rsa -C “user.email”
or
simply ssh-keygen
Other useful links