Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
rb:git-cheatsheet [09/01/2019 11:55]
andrew [Pulling existing repo to local machine]
rb:git-cheatsheet [11/06/2019 12:54] (current)
andrew [git status]
Line 9: Line 9:
  
   - If 2fa is enabled, your github username and password used to log in to the web portal will not work for ''​git clone https://​github.com/​YOUR_REPO'',​ this will return ''​remote:​ Invalid username or password.''​ The solution is to use a ''​Personal Access Token'',​ this is set up in the security section of the Github website config pages. It is described here:- [[https://​help.github.com/​articles/​creating-a-personal-access-token-for-the-command-line/​]]   - If 2fa is enabled, your github username and password used to log in to the web portal will not work for ''​git clone https://​github.com/​YOUR_REPO'',​ this will return ''​remote:​ Invalid username or password.''​ The solution is to use a ''​Personal Access Token'',​ this is set up in the security section of the Github website config pages. It is described here:- [[https://​help.github.com/​articles/​creating-a-personal-access-token-for-the-command-line/​]]
-  - +  - If you have two repos on a machine (OsX) which need two different logins, modify the repo URL to include the username to log in as, this is set in .git/config (eg. url = https://​username@github.com/​username/​pythonapp.git),​ otherwise the github.com keychain access logins will be used. This may be true for linux too. 
 + 
  
 ===== Starting a new repo ===== ===== Starting a new repo =====
Line 28: Line 30:
   Initialised empty Git repository in /​home/​andrew/​ansible/​testplays/​cis-awsLinux2/​.git/​   Initialised empty Git repository in /​home/​andrew/​ansible/​testplays/​cis-awsLinux2/​.git/​
  
 +
 +
 +==== git branch ====
 +
 +| git branch <​name>​ | create new branch |
 +| git branch -b  <​name>​ | create new branch and checkout |
 +| git branch | List branches |
 +| git branch -a | List all branches, local and remote |
 +| git btanch -d <​branch>​ | safe delete branch id merged ok |
 +| git branch -D <​branch>​ | delete *without* warnings |
 +| git push origin --delete <​branch>​ | push deletes to remote master |
 +
 +
 +
 +==== git checkout ====
 +
 +  $ git checkout ajs/​emptyDirWarning
 +  Switched to branch '​ajs/​emptyDirWarning'​
 +  ​
 +  $ git checkout master
 +  Switched to branch '​master'​
 +  Your branch is up-to-date with '​origin/​master'​.
 +
 +Switch to different branch
  
 ==== git add ==== ==== git add ====
Line 116: Line 142:
 The reason for this is that there is only a local master branch created when commits have been done, so create or touch a file, add it and then repush to remote. The reason for this is that there is only a local master branch created when commits have been done, so create or touch a file, add it and then repush to remote.
  
 +
 +Push local branch to remote repo:-
 +
 +
 +  git push --set-upstream origin name-of-localBranch
  
 ==== git pull ==== ==== git pull ====
Line 315: Line 346:
 config@server1:​~/​repo1$ config@server1:​~/​repo1$
 </​code>​ </​code>​
 +
 +
 +==== git rebase ====
 +
 +Use this to merge updates/​changes in Master to local branch.
 +
 +<code git>
 +git status
 +git checkout master
 +git pull
 +git checkout ajs/​branchName
 +git rebase origin/​master
 +git status
 +
 +Resolve any conflicts here. Add changed files again.
 +
 +git depermission.py ​
 +git status
 +git rebase --continue
 +</​code>​
 +
  
  

rb/git-cheatsheet.1547034950.txt.gz · Last modified: 09/01/2019 11:55 by andrew