Clone a git repository
Step 1: Open gitbash
Step 2: Cd into or create desired directory. Then clone the repository:
git clone <insert text under Clone with SSH>
Step 3: If says Permission denied (public key), do the following. Otherwise skip to step 4.
Generate a private/public ed25519 key pair. Enter pass phrase. If you do not want a pass, just press enter through the password prompts.
ssh-keygen -t ed25519 -C "<your email address here>"
Cd into your main directory
cd
cd into ssh
cd .ssh
get list of files in .ssh
ls
Open files in explorer
explorer .
Open id_ed25519.pub with Notepad ++ and copy the key text.
On Gitlab, go to Settings > SSH keys
Paste the public SSH key and click add key
Now you can rerun:
git clone <Link under Clone with SSH>
Step 4:
If you are working on a different branch of the repository, you can switch to it by doing the following. Otherwise, skip this step.
cd into the cloned folder and run:
git checkout <name of branch>
If you get no error message, move on to Step 5.
If .idea is in the repository you will get error message “The following untracked working tree files would be overwritten by checkout:”
Run the following to remove the .idea files:
rm -rf .idea
Now try git checkout
git checkout -- .
Now check git status to make sure that the untracked files are no longer listed. Then run git checkout <name of branch> again.
Step 5: If the remote repository updates and you did not make any changes to the local repository, you can use git pull to update your local repository with the changes. Otherwise, skip this step.
Upload your changes to the online repository
Step 1: After you have made changes to the files using a text editor such as PyCharm, you can now apply these changes to the online repository:
Open Git Bash in the local repository. First run the following to make sure that you are not overwriting changes that others made to the online repository:
git fetch origin
git log origin/<branch name>
A Unix program called less is opened. To see the latest changes to the online (remote) repository, press gg. To see the first changes made, press GG. To scroll up and down, use the up and down arrows.
If others made changes to any of the files in the online repository, you will have to do an extra step before ‘git push’. More on that later!
Step 2: See which files you changed in your local repository.
git status
Step 3: Stage all of the listed files for commit all (except .idea files if they show up).
git add <file1name>.py <file2name>.py
Step 4: Check git status again to see which files are now in green (staged for commit):
git status
Step 5: Show the changes you made to the files that are staged for commit. This is run in the less program.
git diff --staged
Step 6: Commit the changes
git commit
Step 7: Write the comment to appear in gitlab describing your changes. If ViM is used, press i to insert the comment. You can press enter to add another line (but one line is preferable). In ViM, press Esc to leave insert mode and then capital Z twice to save and quit.
Step 8: If in step 1 you saw that others made changes to the online repository, follow this next step. Otherwise, skip to step 9.
git rebase pulls in someone else’s changes and replays your commit on top. Before we can run the script, make sure to first either stash or checkout any unstaged changes which you do not want to push to the online repository. This is especially useful when you have an unstaged .idea file that you do not wish to push.
Run ONE of the following scripts:
1. Stash any unstaged changes (useful for files that you may later want to push, just not now)
git stash
If you ever need to unstash the file, run git stash pop
2. Checkout any unstaged changes (useful for .idea files which you never want to push)
git checkout -- .
Now you can run git rebase:
git rebase origin/<branch name>
If the other person changed the same file that you want to push, a merge conflict will occur. If this happens, go into the text editor you are using (such as PyCharm) and resolve the merge conflict there. Then, run git rebase –continue in Git Bash.
If you get another merge conflict with something you do not want to commit (like .idea), run git checkout — <file name>. Then run git rebase –continue again.
Step 9: Push the changes to the online repository.
git push origin <branch name>
Now see the updated online repository!